concatenate all values of a column

Nishithraj
Posted by Nishithraj under Sql Server category on | Views : 1822
We can append all the values of a specific field to a string variable.
We can use the concatenation operator '+' to achieve this as follows.

DECLARE @ConcatStr VARCHAR(MAX)
SET @ConcatStr= ''
SELECT @ConcatStr= @ConcatStr + FieldName +',' FROM Table
SELECT @ConcatStr

Comments or Responses

Login to post response