Last active
December 15, 2015 01:18
-
-
Save metametaclass/5178680 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| select sum(case Main.AccTrnsHalf_Half* | |
| case | |
| when :OneHalfMode=1 then Main.AccTrnsHalf_Inverse | |
| else 1 | |
| end | |
| when 1 then Main.AccTrnsHalf_Half*AccTrns_MainTotal | |
| else 0 | |
| end) DTotal, | |
| sum(case Main.AccTrnsHalf_Half* | |
| case | |
| when :OneHalfMode=1 then Main.AccTrnsHalf_Inverse | |
| else 1 | |
| end | |
| when -1 then -Main.AccTrnsHalf_Half*AccTrns_MainTotal | |
| else 0 | |
| end) KTotal, | |
| AccTrns_Dept, | |
| Main.AccTrnsHalf_Half, | |
| Main.AccTrnsHalf_Inverse, | |
| coalesce(MainAttrs.ACA_ID,Main.ACCTRNSHALF_Accnt_ID), | |
| coalesce(CorrAttrs.ACA_ID,Corr.ACCTRNSHALF_Accnt_ID) | |
| from AccntTransHalfs Main | |
| join AccntTrans on AccTrns_XmlObj_ID+0=Main.AccTrnsHalf_AccTrns_ID | |
| join AccntTransHalfs Corr on Corr.AccTrnsHalf_AccTrns_ID=Main.AccTrnsHalf_AccTrns_ID and | |
| Corr.AccTrnsHalf_Half=-Main.AccTrnsHalf_Half | |
| join AccountIncidences FltMain on FltMain.AccInc_TblAcc_ID=Main.ACCTRNSHALF_Accnt_ID+0 and | |
| FltMain.AccInc_FltAcc_ID=:fltaccid_main | |
| join AccountIncidences FltCorr on FltCorr.AccInc_TblAcc_ID=Corr.ACCTRNSHALF_Accnt_ID+0 and | |
| FltCorr.AccInc_FltAcc_ID=:fltaccid_corr | |
| left join AccountIncidences MainLvl | |
| join AccountAttributes MainAttrs on MainAttrs.ACA_ID=MainLvl.AccInc_FltAcc_ID | |
| on MainLvl.AccInc_TblAcc_ID=Main.ACCTRNSHALF_Accnt_ID+0 and | |
| MainAttrs.ACA_Level=:acclevel_main | |
| left join AccountIncidences CorrLvl | |
| join AccountAttributes CorrAttrs on CorrAttrs.ACA_ID=CorrLvl.AccInc_FltAcc_ID | |
| on CorrLvl.AccInc_TblAcc_ID=Corr.ACCTRNSHALF_Accnt_ID+0 and | |
| CorrAttrs.ACA_Level=:acclevel_corr | |
| where AccTrns_Datetime>=:month_beg and AccTrns_Datetime<(:month_end+1) and | |
| (AccTrns_Dept=:dept_id or :dept_id=0) and | |
| (:mode=2 or | |
| (Main.AccTrnsHalf_Half* | |
| case | |
| when :OneHalfMode=1 then Main.AccTrnsHalf_Inverse | |
| else 1 | |
| end) = 1) and | |
| --hide one-side transacts with same accounts | |
| (:hidesame=0 or | |
| (coalesce(MainAttrs.ACA_ID,Main.ACCTRNSHALF_Accnt_ID)<>coalesce(CorrAttrs.ACA_ID,Corr.ACCTRNSHALF_Accnt_ID)) or | |
| (Main.AccTrnsHalf_Inverse=Corr.AccTrnsHalf_Inverse)) | |
| group by 3,4,5,6,7 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment