begin
select *
into
from
(
select t.tablename,t.dbtype,t.dbname,t.accidname,t.companyname,t.iyear,t.iPeriod,t.isbook,t.ruleversion,t.indextype,t.rownum,
t.hesuan,t.ccode,t.ccodefx,t.jdfx,t.jsfs,t.indexname
from VW_CO_JC_BalanceSheet_zb as t
where 1=1
and accidname in ($(合并报表-账套名称))
and iyear=$(合并报表-年度)
and iperiod=$(合并报表-期间)
and isbook='$(合并报表-是否包含未记账)'
$(合并报表_报表行号)
$(合并报表_指标名称)
union all
select t.tablename,t.dbtype,t.dbname,t.accidname,t.companyname,t.iyear,t.iPeriod,t.isbook,t.ruleversion,'',t.rownum,
'',t.ccode,t.jdfx as ccodefx,t.jdfx,t.jsfs,t.indexname
from VW_CO_JC_Profit_zb as t
where 1=1
and accidname in ($(合并报表-账套名称))
and iyear=$(合并报表-年度)
and iperiod=$(合并报表-期间)
and isbook='$(合并报表-是否包含未记账)'
$(合并报表_报表行号)
$(合并报表_指标名称)
) as mm
select t.*
into
from CO_JC_Ccode as t
where 1=1
and accidname in ($(合并报表-账套名称))
and iyear=$(合并报表-年度)
select t.dbtype,t.dbname,t.iyear,t.iperiod,isbook,ccode,ccodename,fuzhuhesuan,isdetail,
case when isdetail=0 then 0 else 999 end as isdetail2,
(case when ccodefx='1' then isnull(localqc,0) else 0-isnull(localqc,0) end ) as localqc,
(case when isnull(localqc,0)>0 then isnull(localqc,0) else 0 end ) as localjfqc,
(case when isnull(localqc,0)<0 then abs(isnull(localqc,0)) else 0 end ) as localdfqc,
localjffs,localdffs,localjfytdfs,localdfytdfs,
(case when ccodefx='1' then localqm else 0-isnull(localqm,0) end ) as localqm,
(case when isnull(localqm,0)>0 then isnull(localqm,0) else 0 end ) as localjfqm,
(case when isnull(localqm,0)<0 then abs(isnull(localqm,0)) else 0 end ) as localdfqm,
(case when ccodefx='1' then isnull(wbqc,0) else 0-isnull(wbqc,0) end ) as wbqc,
(case when isnull(wbqc,0)>0 then isnull(wbqc,0) else 0 end ) as wbjfqc,
(case when isnull(wbqc,0)<0 then abs(isnull(wbqc,0)) else 0 end ) as wbdfqc,
wbjffs,wbdffs,wbjfytdfs,wbdfytdfs,
(case when ccodefx='1' then wbqm else 0-isnull(wbqm,0) end ) as wbqm,
(case when isnull(wbqm,0)>0 then isnull(wbqm,0) else 0 end ) as wbjfqm,
(case when isnull(wbqm,0)<0 then abs(isnull(wbqm,0)) else 0 end ) as wbdfqm
into
from VW_CO_JC_ERP_Balance t
where 1=1
and accidname in ($(合并报表-账套名称))
and iyear=$(合并报表-年度)
and iperiod=$(合并报表-期间)
and isbook='$(合并报表-是否包含未记账)'
select a.tablename,a.dbtype,a.dbname,a.accidname,a.companyname,
a.iyear,a.iPeriod,a.isbook,a.ruleversion,a.indextype,a.rownum,
a.ccode as 指标科目,a.ccodefx as 指标科目方向,isnull(a.jdfx,'') 指定方向,
b.ccode as 末级科目,b.ccodename as 末级科目名称,
case when b.ccodefx='1' then '借' else '贷' end as 末级科目方向,a.jsfs,indexname,
case when hesuan='重分类' then '1' else '0' end as isdetail
into
from
inner join
on a.dbname=b.dbname and a.dbtype=b.dbtype and a.iyear=b.iyear
and a.ccode=left(b.ccode,len(a.ccode)) and b.bend=1
where isnull(a.jdfx,'') not in('自借','自贷','自')