• I had already done a PIVOT when I saw you'd already got it!

    ;WITH ctePrepare

    AS

    (SELECT id, name, name + ' (' + CONVERT(VARCHAR, counts) + ')' AS NameWithCount FROM test)

    SELECT id, Cooking + ', ' + Literature + ', ' + Math + ', ' + Reading AS categorycounts

    FROM

    (SELECT id, name, NameWithCount FROM ctePrepare) AS Z

    PIVOT (MAX(NameWithCount) FOR name IN (Cooking, Literature, Math, Reading)) AS pvt