select '个别报表数' as 标题,
t.iyear as 年度,t.iperiod as 期间,t.hbcompany as 合并单位,t.biaoyang as 指标类型,t.rownum as 行号,t.indexname as 指标名称,
t.ordernum as 行次,t1.localmoney as 本币金额,t1.wbmoney as 外币金额
from
(
select *
from
(
select distinct iyear,iperiod,hbcompany
from
(
select distinct iyear,iperiod,companyParent as hbcompany from VW_CO_JC_Account_InvestmentParent01
where 1=1 and invenstmentRatio>0 and iyear=$(合并报表-年度) and iperiod=$(合并报表-期间)
union all
select distinct iyear,iperiod,companyname as hbcompany from VW_CO_JC_Account_InvestmentParent01
where 1=1 and invenstmentRatio>0 and iyear=$(合并报表-年度) and iperiod=$(合并报表-期间)
) as tt
) a
cross join
(select * from VW_CO_HB_index where biaoyang in ('A资产负债表','B资产负债表')) b
)t
left join
(
select 'A资产负债表' as biaoyang, iyear,iperiod,hbcompanyname,rownum,zcindexname as indexname,sum(zclocalqm) as localmoney,sum(zcwbqm) as wbmoney
from CO_GB_BalanceSheet
where isbook = '$(合并报表-是否包含未记账)'
group by iyear,iperiod,hbcompanyname,rownum,zcindexname
union all
select 'B资产负债表' as biaoyang, iyear,iperiod,hbcompanyname,rownum,fzqyindexname as indexname,sum(fzqylocalqm) as localmoney,sum(fzqywbqm) as wbmoney
from CO_GB_BalanceSheet
where isbook = '$(合并报表-是否包含未记账)'
group by iyear,iperiod,hbcompanyname,rownum,fzqyindexname
) t1 on t.iyear=t1.iyear and t.iperiod=t1.iperiod and t.hbcompany=t1.hbcompanyname and t.biaoyang=t1.biaoyang and t.rownum=t1.rownum
where t.indexname is not null
order by t.biaoyang,t.rownum