CREATE table #yourtable ([item] int, [value] varchar(6)) ;

0

Please login or register to vote for this query.

(click on this box to dismiss)

Motor Vehicle Maintenance and Repair Meta

Q&A about the site for mechanics and DIY enthusiast owners of cars, trucks, and motorcycles

CREATE table #yourtable
    ([item] int, [value] varchar(6))
;
    
INSERT INTO #yourtable
    ([item], [value])
VALUES
    (1, 'John'),
    (1, 'jOHN 2'),
    (3, 'John')
;


SELECT  item
       ,STUFF((SELECT ': ' + CAST(value AS VARCHAR(10)) [text()]
         FROM #yourtable
         WHERE item = t.item
         FOR XML PATH(''), TYPE)
        .value('.','NVARCHAR(MAX)'),1,2,' ') List_Output
FROM #yourtable t
GROUP BY item

Enter Parameters

Options:
Switch to main site
loading Hold tight while we fetch your results