Reputation: 55
I am trying to concatenate values in a column when those values correspond to the same ID number. Here's an example of the data:
The query result I want is this:
Here is the code I tried to achieve this result.
SELECT column1,
STUFF((SELECT ', ' + column2
FROM your_table t2
WHERE t1.column1 = t2.column1
FOR XML PATH('')), 1, 2, '') AS concatenated_values
FROM your_table t1
GROUP BY column1;
This code returns question marks (e.g., "????") in many rows. I don't want this. Please help.
Upvotes: 0
Views: 216