日期:2014-05-17 浏览次数:20589 次
select a.AcctGroup,a.CompanyID,a.AcctName,a.AcctNoBE,a.AcctID,b.NetPaid ,
b.ClosingAmtBase,c.fromdateString into #TT
from dbo.D_AcctSegtType a inner join dbo.F_AccountEntry b
on a.AcctID=b.AcctID and a.CompanyID =b.companyid
inner join dbo.D_FiscalDate c on b.FiscalDateID=c.FiscalDateID and b.CompanyID=c.CompanyID
where c.fromdateString='20120401'or c.fromdateString='20120501' and a.AcctGroup='Balance Sheet'
--看学生表例子写的
--运行下面一行报错:Incorrect syntax near '20120401'.
select * from (select * from #TT) a pivot (max(NetPaid) for fromdateString in (20120401,20120501)) b
create table #tb(姓名 varchar(10) , 课程 varchar(10) , 分数 int)
insert into #tb values('张三' , '语文' , 74)
insert into #tb values('张三' , '数学' , 83)
insert into #tb values('张三' , '物理' , 93)
insert into #tb values('李四' , '语文' , 74)
insert into #tb values('李四' , '数学' , 84)
insert into #tb values('李四' , '物理' , 95)
truncate table #tb
select top 5 * from #TT
select * from #tb
select * from (select * from #tb) a pivot (max(分数) for 课程 in (语文,数学,物理)) b