SELECT empid,CAST(orderyear AS INT)AS orderyear,numorders
SELECT empid, orderyear, numorders
declare @table table(empid int, cnt2007 int, cnt2008 int, cnt2009 int)insert into @tableselect 1, 1, 1, 1union allselect 2, 1, 2 ,1union allselect 3, 2, 0, 2select empid, cast((replace([Year], 'cnt','')) as int) as orderyear, value as numorders From ( select * from @table ) UNPIVOT_TABLEunpivot (value for [Year] in (cnt2007,cnt2008,cnt2009)) UNPIVOT_handlewhere value <> 0
declare @table table(empid int, cnt2007 int, cnt2008 int, cnt2009 int)insert into @tableselect 1, 1, 1, 1union allselect 2, 1, 2 ,1union allselect 3, 2, 0, 2select empid, cast((replace([Year], 'cnt','')) as int) as orderyear , value as numorders From ( select * from @table ) UNPIVOT_TABLEunpivot (value for [Year] in (cnt2007,cnt2008,cnt2009)) UNPIVOT_handlewhere value <> 0