Differences

This shows you the differences between two versions of the page.

Link to this comparison view

control_sql_-_vendor_credit_balance_integrity_check [2019/01/27 11:29]
127.0.0.1 external edit
control_sql_-_vendor_credit_balance_integrity_check [2019/02/05 11:29] (current)
admin
Line 23: Line 23:
 <code sql> <code sql>
 SELECT   SELECT  
-    (select DivisionName as Division  +    (SELECT DivisionName AS Division  
-        from EmployeeGroup  +        FROM EmployeeGroup  
-        where coalesce(A.DivisionID, Account.DivisionID) = EmployeeGroup.ID) as Division,+        WHERE COALESCE(A.DivisionID, Account.DivisionID) = EmployeeGroup.ID) AS Division,
     Account.CompanyName,     Account.CompanyName,
     Account.VendorCreditBalance,     Account.VendorCreditBalance,
     GLAmount AS GLCreditBalance,     GLAmount AS GLCreditBalance,
-    coalesce(GLAmount,0) - coalesce(Account.VendorCreditBalance,0) as Difference, +    COALESCE(GLAmount,0) - COALESCE(Account.VendorCreditBalance,0) AS Difference, 
-    Account.ID as AccountID, +    Account.ID AS AccountID, 
-    (select max(EntryDateTime)  +    (SELECT MAX(EntryDateTime)  
-        from GL GL2  +        FROM GL GL2  
-        where GL2.AccountID = Account.ID +        WHERE GL2.AccountID = Account.ID 
-          and GL2.GLAccountID = 25) as LastGLCreditDate+          AND GL2.GLAccountID = 25) AS LastGLCreditDate
 FROM     FROM    
 ( (
-    select  coalesce(DivisionID, 10) as DivisionID,  +    SELECT  COALESCE(DivisionID, 10) AS DivisionID,  
-            AccountID as GLsAccountID,  +            AccountID AS GLsAccountID,  
-            sum(Amount) GLAmount +            SUM(Amount) GLAmount 
-    from GL +    FROM GL 
-    where GLAccountID = 25 +    WHERE GLAccountID = 25 
-    group by coalesce(DivisionID, 10), AccountID +    GROUP BY COALESCE(DivisionID, 10), AccountID 
-    having sum(Amount)  +    HAVING SUM(Amount) <> 
-as +AS 
-full join+FULL JOIN
 ( (
-    select ID as VendorAccountID +    SELECT ID AS VendorAccountID 
-    from Account +    FROM Account 
-    where VendorCreditBalance  +    WHERE VendorCreditBalance <> 
-as on A.GLsAccountID = B.VendorAccountID +AS ON A.GLsAccountID = B.VendorAccountID 
-left join Account on Account.ID = coalesce(A.GLsAccountID, B.VendorAccountID) +  
-where coalesce(A.GLAmount, 0)  coalesce(Account.VendorCreditBalance, 0) +LEFT JOIN Account ON Account.ID = COALESCE(A.GLsAccountID, B.VendorAccountID) 
-order by Division, CompanyName, GLsAccountID+WHERE COALESCE(A.GLAmount, 0) <> COALESCE(Account.VendorCreditBalance, 0) 
 +ORDER BY Division, CompanyName, GLsAccountID
 </code> </code>