Michael Covell
Michael Covell

Reputation: 55

Question marks appearing in query result when I concatenate values from multiple rows

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:

enter image description here

The query result I want is this:

enter image description here

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

Answers (0)

Related Questions