Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
|
control_sql_-_find_gl_out_of_balances [2019/01/27 11:28] 127.0.0.1 external edit |
control_sql_-_find_gl_out_of_balances [2019/02/05 11:18] (current) admin |
||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== Control SQL - Find GL Out of Balance ====== | ====== Control SQL - Find GL Out of Balance ====== | ||
| - | |||
| - | |||
| ===== Explanation of SQL ===== | ===== Explanation of SQL ===== | ||
| + | This query is run to identify any places the GL: | ||
| - | |||
| - | This query is run to identify any places the GL: | ||
| * Is Out of Balance Overall | * Is Out of Balance Overall | ||
| * Is Out of Balance for a Division | * Is Out of Balance for a Division | ||
| * Will result in an improper Balance Sheet/ | * Will result in an improper Balance Sheet/ | ||
| - | | + | |
| * Uses any non-existend GL Accounts | * Uses any non-existend GL Accounts | ||
| - | | + | |
| - | + | ||
| ===== Risk of Data Corruption if Run Improperly ===== | ===== Risk of Data Corruption if Run Improperly ===== | ||
| **None**. This is a selection query and no data is modified in the running of it. | **None**. This is a selection query and no data is modified in the running of it. | ||
| - | |||
| - | |||
| ===== SQL ===== | ===== SQL ===== | ||
| - | |||
| - | |||
| <code sql> | <code sql> | ||
| -- GL Out of Balance Breakdown | -- GL Out of Balance Breakdown | ||
| - | declare | + | |
| - | declare | + | DECLARE |
| + | DECLARE | ||
| SET @StartDate = ' | SET @StartDate = ' | ||
| SET @EndDate | SET @EndDate | ||
| Line 39: | Line 31: | ||
| FROM EmployeeGroup | FROM EmployeeGroup | ||
| WHERE OOBGL.DivisionID = EmployeeGroup.ID) AS Division, | WHERE OOBGL.DivisionID = EmployeeGroup.ID) AS Division, | ||
| - | | + | |
| - | | + | |
| - | + '/' | + | + '/' |
| - | + '/' | + | + '/' |
| AS DateTime ) AS TheDate, | AS DateTime ) AS TheDate, | ||
| OOBGL.TheHour, | OOBGL.TheHour, | ||
| Line 53: | Line 45: | ||
| TransHeader.AccountID, | TransHeader.AccountID, | ||
| OOBGL.TransHeaderID, | OOBGL.TransHeaderID, | ||
| - | (SELECT | + | (SELECT |
| FROM GL GL2 | FROM GL GL2 | ||
| WHERE GL2.TransactionID = OOBGL.TransHeaderID) AS LastGLEntryDate | WHERE GL2.TransactionID = OOBGL.TransHeaderID) AS LastGLEntryDate | ||
| FROM | FROM | ||
| ( | ( | ||
| - | SELECT | + | SELECT |
| COALESCE (TransactionID, | COALESCE (TransactionID, | ||
| - | DatePart(Year, EntryDateTime) AS TheYear, | + | DatePart(YEAR, EntryDateTime) AS TheYear, |
| - | DatePart(Month, EntryDateTime) AS TheMonth, | + | DatePart(MONTH, EntryDateTime) AS TheMonth, |
| - | DatePart(Day, EntryDateTime) AS TheDay, | + | DatePart(DAY, EntryDateTime) AS TheDay, |
| - | DatePart(Hour, EntryDateTime) AS TheHour, | + | DatePart(HOUR, EntryDateTime) AS TheHour, |
| OffBalanceSheet, | OffBalanceSheet, | ||
| SUM(Amount) AS OOBAmount | SUM(Amount) AS OOBAmount | ||
| FROM Ledger | FROM Ledger | ||
| WHERE EntryDateTime BETWEEN @StartDate AND @EndDate | WHERE EntryDateTime BETWEEN @StartDate AND @EndDate | ||
| - | GROUP BY Coalesce(DivisionID, | + | GROUP BY COALESCE(DivisionID, |
| COALESCE (TransactionID, | COALESCE (TransactionID, | ||
| - | DatePart(Year, EntryDateTime), | + | DatePart(YEAR, EntryDateTime), |
| - | DatePart(Month, EntryDateTime), | + | DatePart(MONTH, EntryDateTime), |
| - | DatePart(Day, EntryDateTime), | + | DatePart(DAY, EntryDateTime), |
| - | DatePart(Hour, EntryDateTime), | + | DatePart(HOUR, EntryDateTime), |
| OffBalanceSheet | OffBalanceSheet | ||
| - | HAVING | + | HAVING |
| ) AS OOBGL | ) AS OOBGL | ||
| LEFT OUTER JOIN TransHeader ON TransHeader.ID = OOBGL.TransHeaderID | LEFT OUTER JOIN TransHeader ON TransHeader.ID = OOBGL.TransHeaderID | ||
| - | |||
| LEFT OUTER JOIN Account ON TransHeader.AccountID = Account.ID | LEFT OUTER JOIN Account ON TransHeader.AccountID = Account.ID | ||
| - | |||
| ORDER BY Division, TheDate DESC, TheHour DESC, OrderNumber, | ORDER BY Division, TheDate DESC, TheHour DESC, OrderNumber, | ||
| + | |||
| </ | </ | ||
| + | ===== Version Information ===== | ||
| - | + | | |
| - | ===== Version Information ===== | + | |
| - | | + | |
| * Version : | * Version : | ||
| - | |||
| - | |||