2

I have a table (name- tbl2) with 21 column but I want to combine multiple rows records in a row by using a unique reference number as below:

Table Field and Records Type

enter image description here

Expected Result:

enter image description here

Please help me to resolve this issue.

2 Answers2

2

Try the below query will solve your problem:

SELECT ID, STUFF(
     (SELECT ', ' + CAST(Item AS VARCHAR(20)) [text]
     FROM TBL12
     WHERE ID = t.ID
     FOR XML PATH(''), TYPE)
    .value('.','NVARCHAR(MAX)'),1,2,' ') Items
FROM TBL12 t
GROUP BY ID

Since you add many tags in the post, I solved in MSSQL using STUFF.
Working fiddle: http://sqlfiddle.com/#!3/d805d/4

Arulkumar
  • 1,137
  • 9
  • 25
1

This is most easily accomplished in an Access query by using the ConcatRelated() function. For more information see the following question on Stack Overflow:

Combine values from related rows into a single concatenated string value

Gord Thompson
  • 1,277
  • 9
  • 13