Advertisement
bytecoded

TempDB Query Top 5 1C

Mar 31st, 2019
369
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.60 KB | None | 0 0
  1. SELECT ALLOWED
  2. Accounts.Entity AS Entity,
  3. Companies.Ref AS Company,
  4. Accounts.Contract AS Contract,
  5. Accounts.Document AS Document,
  6. Accounts.Document.Date AS DocumentDate,
  7. Accounts.Document.Number AS DocumentNumber,
  8. Accounts.Contract.AccountsCurrency AS Currency,
  9. DATEDIFF(Accounts.Document.Date, &EndOfPeriod, DAY) AS DaysOverdue,
  10. SUM(Accounts.AmountBalance) AS Amount,
  11. SUM(Accounts.AmountCurBalance) AS AmountCur,
  12. Accounts.Document.Responsible AS ResponsibleDoc,
  13. Accounts.Document.SalesExecutive AS SalesExecutiveDoc,
  14. Accounts.Document.Department AS DepartmentDoc
  15. INTO Accounts
  16. FROM
  17. AccumulationRegister.CustomerAccounts.Balance(&EndOfPeriod {(&EndOfPeriod)}, ) AS Accounts
  18. LEFT JOIN Catalog.Companies AS Companies
  19. ON Accounts.Company = Companies.Ref
  20. WHERE
  21. Accounts.Document <> UNDEFINED
  22. AND Accounts.AccountsType = VALUE(Enum.PaymentTypes.Debt)
  23.  
  24. GROUP BY
  25. Accounts.Document,
  26. Accounts.Entity,
  27. Accounts.Contract,
  28. Accounts.Document.Date,
  29. Accounts.Document.Number,
  30. Accounts.Contract.AccountsCurrency,
  31. DATEDIFF(Accounts.Document.Date, &EndOfPeriod, DAY),
  32. Companies.Ref
  33.  
  34. UNION ALL
  35.  
  36. SELECT
  37. AccountsReceivableDeferredBalance.Entity,
  38. Companies.Ref,
  39. AccountsReceivableDeferredBalance.Contract,
  40. AccountsReceivableDeferredBalance.Document,
  41. AccountsReceivableDeferredBalance.Document.Date,
  42. AccountsReceivableDeferredBalance.Document.Number,
  43. AccountsReceivableDeferredBalance.Contract.AccountsCurrency,
  44. DATEDIFF(AccountsReceivableDeferredBalance.Document.Date, &EndOfPeriod, DAY),
  45. SUM(AccountsReceivableDeferredBalance.AmountBalance),
  46. SUM(AccountsReceivableDeferredBalance.AmountCurBalance),
  47. AccountsReceivableDeferredBalance.Document.Responsible,
  48. AccountsReceivableDeferredBalance.Document.SalesExecutive,
  49. AccountsReceivableDeferredBalance.Document.Department
  50. FROM
  51. AccumulationRegister.AccountsReceivableDeferred.Balance(&EndOfPeriod {(&EndOfPeriod)}, ) AS AccountsReceivableDeferredBalance
  52. LEFT JOIN Catalog.Companies AS Companies
  53. ON AccountsReceivableDeferredBalance.Company = Companies.Ref
  54. WHERE
  55. AccountsReceivableDeferredBalance.Document <> UNDEFINED
  56. AND AccountsReceivableDeferredBalance.AccountsType = VALUE(Enum.PaymentTypes.Debt)
  57. AND &IncludingCheques
  58.  
  59. GROUP BY
  60. AccountsReceivableDeferredBalance.Entity,
  61. AccountsReceivableDeferredBalance.Contract,
  62. AccountsReceivableDeferredBalance.Document,
  63. AccountsReceivableDeferredBalance.Document.Date,
  64. AccountsReceivableDeferredBalance.Document.Number,
  65. AccountsReceivableDeferredBalance.Contract.AccountsCurrency,
  66. DATEDIFF(AccountsReceivableDeferredBalance.Document.Date, &EndOfPeriod, DAY),
  67. Companies.Ref
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement