Answers for "concatenate text from multiple rows into a single text stringin SQL Server"

SQL
0

concatenate text from multiple rows into a single text stringin SQL Server

SELECT Main.SubjectID,
       LEFT(Main.Students,Len(Main.Students)-1) As "Students"
FROM
    (
        SELECT DISTINCT ST2.SubjectID, 
            (
                SELECT ST1.StudentName + ',' AS [text()]
                FROM dbo.Students ST1
                WHERE ST1.SubjectID = ST2.SubjectID
                ORDER BY ST1.SubjectID
                FOR XML PATH (''), TYPE
            ).value('text()[1]','nvarchar(max)') [Students]
        FROM dbo.Students ST2
    ) [Main]
Posted by: Guest on March-04-2022

Code answers related to "concatenate text from multiple rows into a single text stringin SQL Server"

Code answers related to "SQL"

Browse Popular Code Answers by Language