Вы, кажется, хотите подзапрос:
select 'header' as custom_col, t.*
from ( <dynamic query>
) t;
Вы также можете использовать временную таблицу:
SELECT [YR_4, [YR_3], [YR_2], [YR_1] INTO #Temptable
FROM (SELECT CASE WHEN yr = 9999
THEN 'A Medians'
ELSE cast(yr AS VARCHAR(10))
END AS yr, yrdes
FROM #years2
) AS t
PIVOT ( MAX(yr) FOR yrdes IN ([YR_4], [YR_3], [YR_2], [YR_1] )
) t1;