A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
Hi @Will Faulkner ,
Please refer to:
declare @test table (REFNO int, FIRSTNAME char(15), LASTNAME char(15))
INSERT INTO @test values(1,'BILL','FAULKNER'),(2 ,'BILL', 'FAULKNER')
SELECT FIRSTNAME, LASTNAME
, STUFF((SELECT ',' + CAST(REFNO AS VARCHAR(30)) AS [text()]
FROM @test AS O
WHERE O.FIRSTNAME = C.FIRSTNAME and O.LASTNAME = C.LASTNAME
FOR XML PATH('')), 1, 1, NULL) AS REFNO
FROM @test AS c
GROUP BY FIRSTNAME, LASTNAME
Regards
Echo
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.