• If [Qual] is not needed in the result set, just exclude it .

    -- Query 1 and 2 combined

    SELECT DISTINCT

    StudentUID ,

    Qual

    INTO #A

    FROM [dbo].[Mytable]

    WHERE RegYear < 2014;

    SELECT A.StudentUID ,

    STUFF(( SELECT '; ' + C.Qual

    FROM #A C

    WHERE ( C.StudentUID = A.StudentUID )

    FOR

    XML PATH(''))

    ,1,2,'') AS [QualCode]

    INTO #B

    FROM #A A

    WHERE A.StudentUID IN ( 8314, 241401 )

    GROUP BY A.StudentUID

    ORDER BY 1;

    SELECT * FROM #B;

    DROP TABLE #A;

    DROP TABLE #B;