日期:2014-05-17 浏览次数:20725 次
--整理
select a.CompanyID,a.SegtID,a.SegtName,a.AcctNoBE,a.AcctName,a.AcctID,
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 a.AcctGroup='Balance Sheet' and fromdateString between '20110401' and '20121201'
--列转行
declare @datename varchar(300)
select @datename=ISNULL (@datename+',','')+quotename ([fromdatestring])from #TT group by [fromdatestring]
order by [fromdatestring]
insert into [dbo].[RPT_resultA3_restart](
[CompanyID] ,
[SegtID] ,
[Segtname] ,
[acctnobe] ,
[acctname] ,
[acctid] ,
[Mtd201104] ,
[Mtd201105] ,
[Mtd201106] ,
[Mtd201107] ,
[Mtd201108] ,
[Mtd201109] ,
[Mtd201110] ,
[Mtd201111] ,
[Mtd201112] ,
[Mtd201201] ,
[Mtd201202] ,
[Mtd201203] ,
[Mtd201204] ,
[Mtd201205] ,
[Mtd201206] ,
[Mtd201207] ,
[Mtd201208] ,
[Mtd201209] ,
[Mtd201210]
)
exec('select *from #TT pivot (max([closingamtbase])for [fromdatestring] in ('+@datename+'))b')