Hi,
A few days ago one of my friend asked me about how to concatenate all the rows in a table or some of the rows in a table in a string in the SQL Server. The first idea was to create a user defined function, which would take the column name and return the concatenated value of all the rows in that column.
But a little later I found there is an inbuilt function in TSQL for the same. We can use the coalesce function to get the result of all the rows in a column in TSQL. Here is an example of the same
SELECT COALESCE(@column1 + ',', '') + column1
FROM Table1
So if table1 had following records
Column1
aa
bb
cc
dd
The result of the query will be aabbccdd
So
Vikram