Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SELECT ALLOWED
- Q_000_T_001.Fld11293 Q_000_F_000,
- Q_000_T_001.Fld11295 Q_000_F_001,
- (Q_000_T_001.Fld11302Turnover - Q_000_T_001.Fld11303Turnover) Q_000_F_002,
- Q_000_T_002.ID Q_000_F_003,
- 0 Q_000_F_004
- INTO #Ta4b8a2fa5b44478aba6072979a9df658
- FROM
- (SELECT Fld11293, Fld11295, SUM(Fld11303) AS Fld11303Turnover, SUM(Fld11302) AS Fld11302Turnover FROM AccumRg11289 WHERE Period >= DATETIME(2019,3,1) AND Period <= DATETIME(2019,3,27,23,59,59) AND Active GROUP BY Fld11293, Fld11295 HAVING Fld11303Turnover <> 0 OR Fld11302Turnover <> 0) Q_000_T_001 LEFT JOIN Reference42 Q_000_T_002 ON (CASE
- WHEN Q_000_T_001.Fld11293 REFS Document233 THEN
- CAST(Q_000_T_001.Fld11293 AS REF(Document233)).Fld4625
- WHEN Q_000_T_001.Fld11293 REFS Document212 THEN
- CAST(Q_000_T_001.Fld11293 AS REF(Document212)).Fld3516
- WHEN Q_000_T_001.Fld11293 REFS Document234 THEN
- CAST(Q_000_T_001.Fld11293 AS REF(Document234)).Fld4774
- WHEN Q_000_T_001.Fld11293 REFS Document263 THEN
- CAST(Q_000_T_001.Fld11293 AS REF(Document263)).Fld6287
- WHEN Q_000_T_001.Fld11293 REFS Document216 THEN
- CAST(Q_000_T_001.Fld11293 AS REF(Document216)).Fld3845
- WHEN Q_000_T_001.Fld11293 REFS Document215 THEN
- CAST(Q_000_T_001.Fld11293 AS REF(Document215)).Fld3734
- WHEN Q_000_T_001.Fld11293 REFS Document213 THEN
- CAST(Q_000_T_001.Fld11293 AS REF(Document213)).Fld3600
- WHEN Q_000_T_001.Fld11293 REFS Document199 THEN
- CAST(Q_000_T_001.Fld11293 AS REF(Document199)).Fld2840
- ELSE NULL END
- = Q_000_T_002.ID)
- UNION ALL
- SELECT
- Q_001_T_001.Fld10332,
- Q_001_T_001.Fld10328,
- NULL,
- Q_001_T_001.Fld10330,
- Q_001_T_001.Fld10334Expense
- FROM
- (SELECT Recorder AS Recorder, Fld10332, Fld10328, Fld10330, SUM(CASE WHEN RecordKind = 0 THEN 0 ELSE Fld10334 END) AS Fld10334Expense FROM AccumRg10327 WHERE Period >= DATETIME(2019,3,1) AND Period <= DATETIME(2019,3,27,23,59,59) AND Active AND (TRUE) AND RecordKind = 1 GROUP BY Recorder, Fld10332, Fld10328, Fld10330 HAVING Fld10334Expense <> 0) Q_001_T_001
- WHERE
- (Q_001_T_001.Recorder REFS Document211)
- UNION ALL
- SELECT
- Q_002_T_001.Fld10540,
- Q_002_T_001.Fld10536,
- NULL,
- Q_002_T_001.Fld10538,
- Q_002_T_001.Fld10544Expense
- FROM
- (SELECT Recorder AS Recorder, Fld10538, Fld10540, Fld10536, SUM(CASE WHEN RecordKind = 0 THEN 0 ELSE Fld10544 END) AS Fld10544Expense FROM AccumRg10535 WHERE Period >= DATETIME(2019,3,1) AND Period <= DATETIME(2019,3,27,23,59,59) AND Active AND RecordKind = 1 GROUP BY Recorder, Fld10538, Fld10540, Fld10536 HAVING Fld10544Expense <> 0) Q_002_T_001
- WHERE
- (NOT((CASE
- WHEN Q_002_T_001.Recorder REFS Document233 THEN
- CAST(Q_002_T_001.Recorder AS REF(Document233)).Fld4634
- WHEN Q_002_T_001.Recorder REFS Document212 THEN
- CAST(Q_002_T_001.Recorder AS REF(Document212)).Fld3521
- WHEN Q_002_T_001.Recorder REFS Document234 THEN
- CAST(Q_002_T_001.Recorder AS REF(Document234)).Fld4782
- WHEN Q_002_T_001.Recorder REFS Document253 THEN
- CAST(Q_002_T_001.Recorder AS REF(Document253)).Fld5727
- WHEN Q_002_T_001.Recorder REFS Document259 THEN
- CAST(Q_002_T_001.Recorder AS REF(Document259)).Fld6145
- WHEN Q_002_T_001.Recorder REFS Document216 THEN
- CAST(Q_002_T_001.Recorder AS REF(Document216)).Fld3852
- WHEN Q_002_T_001.Recorder REFS Document209 THEN
- CAST(Q_002_T_001.Recorder AS REF(Document209)).Fld3325
- WHEN Q_002_T_001.Recorder REFS Document215 THEN
- CAST(Q_002_T_001.Recorder AS REF(Document215)).Fld3739
- WHEN Q_002_T_001.Recorder REFS Document258 THEN
- CAST(Q_002_T_001.Recorder AS REF(Document258)).Fld6057
- WHEN Q_002_T_001.Recorder REFS Document211 THEN
- CAST(Q_002_T_001.Recorder AS REF(Document211)).Fld3444
- WHEN Q_002_T_001.Recorder REFS Document248 THEN
- CAST(Q_002_T_001.Recorder AS REF(Document248)).Fld5366
- WHEN Q_002_T_001.Recorder REFS Document255 THEN
- CAST(Q_002_T_001.Recorder AS REF(Document255)).Fld5860
- WHEN Q_002_T_001.Recorder REFS Document210 THEN
- CAST(Q_002_T_001.Recorder AS REF(Document210)).Fld3350
- ELSE NULL END
- REFS Document211))) AND ((Q_002_T_001.Recorder REFS Document259) OR (Q_002_T_001.Recorder REFS Document255))
- UNION ALL
- SELECT
- Q_003_T_001.Fld10332,
- Q_003_T_001.Fld10328,
- NULL,
- Q_003_T_001.Fld10330,
- NULL
- FROM
- (SELECT Recorder AS Recorder, Fld10332, Fld10328, Fld10330, SUM(CASE WHEN RecordKind = 0 THEN Fld10334 ELSE 0 END) AS Fld10334Receipt, SUM(CASE WHEN RecordKind = 0 THEN 0 ELSE Fld10334 END) AS Fld10334Expense, SUM(CASE WHEN RecordKind = 0 THEN Fld10335 ELSE 0 END) AS Fld10335Receipt, SUM(CASE WHEN RecordKind = 0 THEN 0 ELSE Fld10335 END) AS Fld10335Expense FROM AccumRg10327 WHERE Period >= DATETIME(2019,3,1) AND Period <= DATETIME(2019,3,27,23,59,59) AND Active AND (TRUE) GROUP BY Recorder, Fld10332, Fld10328, Fld10330 HAVING Fld10334Receipt <> 0 OR Fld10334Expense <> 0 OR Fld10335Receipt <> 0 OR Fld10335Expense <> 0) Q_003_T_001
- WHERE
- (Q_003_T_001.Recorder REFS Document209)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement