create table #temp(Name varchar(20),year varchar(20),value varchar(20))
insert into #temp
select 'A','2009','1' union all
select 'A','2010','2' union all
select 'A','2011','3' union all
select 'B','2009','11' union all
select 'B','2010','22' union all
select 'B','2011','33'
declare @sql varchar(500)
set @sql = 'select Name'
select @sql=@sql+',max(case year when '''+[year]+''' then value end) ['+[year]+']'
from (select distinct [year] from #temp) as a
set @sql = @sql +' from #temp group by Name'
exec(@sql)
------解决方案--------------------