lee writes "I read Article ID # 2368 "Using COALESCE to Build Comma-Delimited String" and found it very interesting. However, I could not think of a way to use the simple approach without cursors to collapse a column with N rows to single column rowset. This method seems to be limited to one subset of rows at a time. I see no way to use this with a correlated subquery - So I conclude that I have execute a select statement for each set of rows that I would like to do this transformation on. I don't want that conclusion.Here's the example from the original article:DECLARE @EmployeeList varchar(100)SELECT @EmployeeList = COALESCE(@EmployeeList + ', ', '') + CAST(Emp_UniqueID AS varchar(5))FROM SalesCallsEmployeesWHERE SalCal_UniqueID = 1SELECT @EmployeeList
I would like to do something like:Given the recordset (from a subquery):ID Name Depth Group----------------------1 Home 1 12 About 2 13 Detail 3 14 Document 4 11 Home 1 26 Contact 2 27 Detail 3 28 Document 4 2
I would like to get to:Name Group--------------------------------Home,About,Detail,Document 1Home,Contact,Detail,Document 2
Using just one query instead of a slow cursor."