Tuesday, December 18, 2007

How to concatenate all the values from a column and return a single row?

How to concatenate all the values from a column and return a single row?
----------------------------------------------------------------------------------

It was possible to concatenate a series of strings to return a single column, in a sort of analogous manner to sum summing all of the numbers in a column. However, this was not a 'feature' but a bug, so if you are running an EBF that has the fix for CR 210688, this is no longer possible.

(Obsolete:) Use a case statement, a la,

DECLARE @string_var varchar(255)
SELECT @string_var = ""
SELECT @string_var = @string_var +
( CASE 1 WHEN 1 THEN char_col
END )
FROM tbl_a

PRINT "%1!", @string_var
GO

No comments: