Reputation: 765
Can I somehow do this in mssql query alone, no SP or declares? Because I am going to embed this select in my Powerbuilder.
ID text
1 a
1 b
1 c
2 a
2 d
3 e
into
ID text
1 abc
2 ad
3 e
Upvotes: 0
Views: 258
Reputation: 4151
Try like below Query
SELECT
ID,
text=
replace(
STUFF((SELECT ','+text FROM test WHERE ID=A.ID FOR XML PATH('')) , 1 , 1 , '' )
,',','')
FROM
test A group by ID
Upvotes: 0
Reputation: 125620
I'm not sure I understood your question, but check out this DEMO:
SELECT DISTINCT
ID,
(SELECT ''+text FROM Test WHERE ID=A.ID FOR XML PATH('')) AS text
FROM
Test A
Results:
ID TEXT
1 abc
2 ad
3 e
Upvotes: 2