Advertisement
bytecoded

Untitled

Mar 28th, 2019
378
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.71 KB | None | 0 0
  1. SELECT ALLOWED
  2. Q_000_T_001.Fld11293 Q_000_F_000,
  3. Q_000_T_001.Fld11295 Q_000_F_001,
  4. (Q_000_T_001.Fld11302Turnover - Q_000_T_001.Fld11303Turnover) Q_000_F_002,
  5. Q_000_T_002.ID Q_000_F_003,
  6. 0 Q_000_F_004
  7. INTO #Ta4b8a2fa5b44478aba6072979a9df658
  8. FROM
  9. (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
  10. WHEN Q_000_T_001.Fld11293 REFS Document233 THEN
  11. CAST(Q_000_T_001.Fld11293 AS REF(Document233)).Fld4625
  12. WHEN Q_000_T_001.Fld11293 REFS Document212 THEN
  13. CAST(Q_000_T_001.Fld11293 AS REF(Document212)).Fld3516
  14. WHEN Q_000_T_001.Fld11293 REFS Document234 THEN
  15. CAST(Q_000_T_001.Fld11293 AS REF(Document234)).Fld4774
  16. WHEN Q_000_T_001.Fld11293 REFS Document263 THEN
  17. CAST(Q_000_T_001.Fld11293 AS REF(Document263)).Fld6287
  18. WHEN Q_000_T_001.Fld11293 REFS Document216 THEN
  19. CAST(Q_000_T_001.Fld11293 AS REF(Document216)).Fld3845
  20. WHEN Q_000_T_001.Fld11293 REFS Document215 THEN
  21. CAST(Q_000_T_001.Fld11293 AS REF(Document215)).Fld3734
  22. WHEN Q_000_T_001.Fld11293 REFS Document213 THEN
  23. CAST(Q_000_T_001.Fld11293 AS REF(Document213)).Fld3600
  24. WHEN Q_000_T_001.Fld11293 REFS Document199 THEN
  25. CAST(Q_000_T_001.Fld11293 AS REF(Document199)).Fld2840
  26. ELSE NULL END
  27. = Q_000_T_002.ID)
  28. UNION ALL
  29. SELECT
  30. Q_001_T_001.Fld10332,
  31. Q_001_T_001.Fld10328,
  32. NULL,
  33. Q_001_T_001.Fld10330,
  34. Q_001_T_001.Fld10334Expense
  35. FROM
  36. (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
  37. WHERE
  38. (Q_001_T_001.Recorder REFS Document211)
  39.  
  40. UNION ALL
  41. SELECT
  42. Q_002_T_001.Fld10540,
  43. Q_002_T_001.Fld10536,
  44. NULL,
  45. Q_002_T_001.Fld10538,
  46. Q_002_T_001.Fld10544Expense
  47. FROM
  48. (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
  49. WHERE
  50. (NOT((CASE
  51. WHEN Q_002_T_001.Recorder REFS Document233 THEN
  52. CAST(Q_002_T_001.Recorder AS REF(Document233)).Fld4634
  53. WHEN Q_002_T_001.Recorder REFS Document212 THEN
  54. CAST(Q_002_T_001.Recorder AS REF(Document212)).Fld3521
  55. WHEN Q_002_T_001.Recorder REFS Document234 THEN
  56. CAST(Q_002_T_001.Recorder AS REF(Document234)).Fld4782
  57. WHEN Q_002_T_001.Recorder REFS Document253 THEN
  58. CAST(Q_002_T_001.Recorder AS REF(Document253)).Fld5727
  59. WHEN Q_002_T_001.Recorder REFS Document259 THEN
  60. CAST(Q_002_T_001.Recorder AS REF(Document259)).Fld6145
  61. WHEN Q_002_T_001.Recorder REFS Document216 THEN
  62. CAST(Q_002_T_001.Recorder AS REF(Document216)).Fld3852
  63. WHEN Q_002_T_001.Recorder REFS Document209 THEN
  64. CAST(Q_002_T_001.Recorder AS REF(Document209)).Fld3325
  65. WHEN Q_002_T_001.Recorder REFS Document215 THEN
  66. CAST(Q_002_T_001.Recorder AS REF(Document215)).Fld3739
  67. WHEN Q_002_T_001.Recorder REFS Document258 THEN
  68. CAST(Q_002_T_001.Recorder AS REF(Document258)).Fld6057
  69. WHEN Q_002_T_001.Recorder REFS Document211 THEN
  70. CAST(Q_002_T_001.Recorder AS REF(Document211)).Fld3444
  71. WHEN Q_002_T_001.Recorder REFS Document248 THEN
  72. CAST(Q_002_T_001.Recorder AS REF(Document248)).Fld5366
  73. WHEN Q_002_T_001.Recorder REFS Document255 THEN
  74. CAST(Q_002_T_001.Recorder AS REF(Document255)).Fld5860
  75. WHEN Q_002_T_001.Recorder REFS Document210 THEN
  76. CAST(Q_002_T_001.Recorder AS REF(Document210)).Fld3350
  77. ELSE NULL END
  78. REFS Document211))) AND ((Q_002_T_001.Recorder REFS Document259) OR (Q_002_T_001.Recorder REFS Document255))
  79.  
  80. UNION ALL
  81. SELECT
  82. Q_003_T_001.Fld10332,
  83. Q_003_T_001.Fld10328,
  84. NULL,
  85. Q_003_T_001.Fld10330,
  86. NULL
  87. FROM
  88. (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
  89. WHERE
  90. (Q_003_T_001.Recorder REFS Document209)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement