I have a table with the following data:
ID CAT TYPE SUBPRODUCT
--- ---- ------ ----------------
1 1 1 AA
2 1 1 BB
3 1 2 CC
I’d like to get the data like this:
CAT TYPE SUBPRODUCT
----- ------ ---------------
1 1 AA,BB
1 2 CC
pls reply me what should i do.
Thanks.
You can use
FOR XML PATH. While a bit hard to read, afaik it currently is the most concise way to concatenate strings.Breakdown
FOR XML PATHconcatenates all values that match the subselectSTUFFremoves the leading commaSQL Statement
Test script