Here is a non-dynamic way to do it. How many possible [week] values are in your table? If it is just 1-52 then you can just extend the "[week] in ()" list.declare @t table (ORDERS int, SITE varchar(10), WEEK int)insert @tselect 27, 'NSS', 1 union allselect 24, 'NSC', 1 union allselect 17, 'NSM', 1 union allselect 12, 'NSC', 2 union allselect 11, 'NSM', 2 union allselect 78, 'NSS', 2select p.* from (select * from @T) spivot (max(orders) for [week] in ([1],[2])) pOUTPUT:SITE 1 2---------- ----------- -----------NSC 24 12NSM 17 11NSS 27 78
Be One with the OptimizerTG