スタックオーバーフローを使うのはこれが初めてで、
クエリの問題があります。4 つのテーブルがあります (左結合)
年と期間、およびアカウント コードでフィルター処理されます。
これはクエリです:
select a.fyear,a.aperiod,c.trx_amt
,e.acct_cd,e.active_status
,ISNULL((select
openingBalance=SUM(a.trx_amt)
from
gl_pendjnls a
left join gl_jlhdr b on a.idxjlhdr = b.idx
left join v_acctperiod c on b.idxperiod = c.idx
right join v_gl_chart d on a.idxcoa = d.idx
where c.fyear < = 2013 and c.aperiod < 10
and d.acct_cd = e.acct_cd
group by d.acct_cd
),0) as openingBalance
,ISNULL((select
closingBalance=SUM(a.trx_amt) + c.trx_amt
from
gl_pendjnls a
left join gl_jlhdr b on a.idxjlhdr = b.idx
left join v_acctperiod f on b.idxperiod = f.idx
left join v_gl_chart d on a.idxcoa = d.idx
where f.fyear < = 2013 and f.aperiod < 10
and d.acct_cd = e.acct_cd
group by d.acct_cd
),0) as closingBalance
from v_acctperiod a
left join gl_jlhdr b on a.idx = b.idxperiod
left join gl_pendjnls c on b.idx = c.idxjlhdr
left join v_gl_chart e on c.idxcoa = e.idx
where e.active_status = 'Y'
and a.fyear = 2013 and a.aperiod = 10
and e.acct_cd = '111-01-201'
結果と私が望む結果:
a.fyear を = 2013 および a.period = 11 に変更し、e.acct_cd = '111-01-201' を削除した場合
データーがない、
私が欲しいのは、データ、最後の期間の期首残高からの acct_cd で構成される新しい行であるため、新しい行データは、最後の期間の期首残高からの acct_cd のみで構成されます。
誰かが助けることができますか?ご清聴ありがとうございました。