Possible Duplicate:
Concatenate many rows into a single text string?
I have 2 tables in SQL Server 2008 database - tblQuestion and tblSummary. I'm selecting QuestionIDs from tblQuestion as follows.
SELECT QuestionId from tblQuestion WHERE Status='Completed';
The result is as follows (from multiple records),
QuestionId
----------
1
2
5
7
8
9
[6 rows]
Now, I need to insert above selected IDs to "CompletedSections" column (which is VARCHAR type) in tblSummary. It should be inserted as a CSV like format - 1,2,5,7,8,9
For example, if I select those from tblSummary will be as follows.
SELECT CompletedSections FROM tblSummary WHERE <Some Condition>
Result should be,
CompletedSections
-----------------
1,2,5,7,8,9
[1 row]
How this can be done at the database level using t-SQL (not using any programming language like C#)? I'm hoping to implement this with t-SQL using a scheduled SQL SP/ Function/ Trigger.
Thanks,
Chatur