日期:2014-05-17 浏览次数:20591 次
create table 表T
(NAME varchar(10),KJ int,BZ varchar(10),RQ varchar(15))
insert into 表T
select 'A',0,'不正确','2013/12/3' union all
select 'A',1,'存在问题','2013/12/1' union all
select 'B',1,'正确','2013/12/1' union all
select 'B',0,'注意','2013/12/3' union all
select 'B',1,'可能','2013/12/2' union all
select 'A',1,'行','2013/12/2'
declare @tsql varchar(6000)
select @tsql=isnull(@tsql+',','')
+'max(case when rn='+rtrim(number)+' then KJ else '''' end) ''KJ'+rtrim(number)+''', '
+'max(case when rn='+rtrim(number)+' then BZ else '''' end) ''BZ'+rtrim(number)+''' '
from master.dbo.spt_values
where type='P' and number between 1 and
(select max(c) from
(select count(1) 'c' from 表T group by NAME) t)
select @tsql='select NAME,'+@tsql
&nb