combine rows into one row

  • Not sure if this is possible . . . .

  • I believe i need to use STUFF and/or XML functions but get lost in the weeds.

  • CREATE TABLE #d(
     HTS_NUM CHAR(4),
     Ctry CHAR(2),
     GA_REQ_CODE CHAR(3)
     );
    GO
    INSERT INTO #d VALUES ('1062','US','FD3'),('1062','US','FW2'),('1062','US','FD3');
    SELECT DISTINCT HTS_NUM
     , Ctry
     ,stuff((
        SELECT ', ' + cast(GA_REQ_CODE as varchar(max))
        FROM #d
        FOR XML PATH('')
        ), 1, 2, '') AS lst
    FROM #d
    ORDER BY HTS_Num, Ctry;

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply