- Example Data Declare @t Table (ID INT, Value Varchar (10)) Insert @t Select 1, 'Aa'Union All Select 2,' Aaa'Union All Select 2, 'BBB 'Union All SELECT 2,' CCC '
- Query processing Select * from (Select Distinct IDFROM @T) AOUTER Apply (SELECT [VALUES] = Stuff (Replace (Replace (Select Value from @t nwhere id = a.idfor xml auto), ' ','), 1, 1, '))
/ * - Result ID VALUES -------------------------- 1 AA, BB2 AAA, BBB, CCC
(2 lines affected) - * /