if object_id('tempdb..#tb') is not null
drop table #tb
select fworkno,convert(varchar(100),date,112) date,classes_id into #tb from ck_scheduling where date<'2012-10-07'
declare @f varchar(max),
@sql varchar(max)
set @f = stuff(( select distinct ',[' + convert(varchar(10),date,112) + ']' from #tb for xml path('')),1,1,'')
set @sql='select * from #tb pivot (max(classes_id) for date in ('+@f+'))a'
print @sql
exec(@sql)