Try this :-
CREATE TABLE #Sample ([SO Number] INT, [Line Number] INT)
INSERT INTO #Sample ([SO Number],[Line Number]) VALUES (123,6)
INSERT INTO #Sample ([SO Number],[Line Number]) VALUES (123,189)
INSERT INTO #Sample ([SO Number],[Line Number]) VALUES (456,34)
SELECT ID,
STUFF((
SELECT ', ' + cast([Line Number] as varchar(max) )
FROM #Sample
WHERE ([SO Number] = a.[SO Number])
FOR XML PATH (''))
,1,2,'') AS b
FROM #Sample a
GROUP BY [SO Number]
Edit :
XML PATH (''):Is used to retrieve the column values seperated by comma
Ex:- ,6,189,34
STUFF: Is used to insert a string into another string .The expression is
STUFF ( character_expression , start , length ,character_expression )
Start length is 1 since we have to replace the first comma created by XML PATH .
Length is 1 for the space ''
which is being inserted
So even if you have 20K rows the expression will remain same as 1,2 is used to insert space