Differences

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

Link to this comparison view

control_sql_-_customer_credit_balance_integrity_check [2019/01/27 11:28]
127.0.0.1 external edit
control_sql_-_customer_credit_balance_integrity_check [2019/02/05 11:28]
admin
Line 22: Line 22:
  
 <code sql> <code sql>
-select   +SELECT   
-    (select DivisionName  +    (SELECT DivisionName  
-        from Division  +        FROM Division  
-        where Coalesce(GLDivisionID, OrderDivisionID) = Division.ID) as Division, +        WHERE COALESCE(GLDivisionID, OrderDivisionID) = Division.ID) AS Division, 
-    (select CompanyName  +    (SELECT CompanyName  
-        from Account +        FROM Account 
-        where ID = coalesce(B.AccountID, A.GLsAccountID)) as CompanyName,+        WHERE ID = COALESCE(B.AccountID, A.GLsAccountID)) AS CompanyName,
     GLAmount AS GLCreditBalance,     GLAmount AS GLCreditBalance,
-    B.CreditBalance as CustomerCreditBalance, +    B.CreditBalance AS CustomerCreditBalance, 
-    coalesce(GLAmount, 0) - coalesce(B.CreditBalance,0) as Difference, +    COALESCE(GLAmount, 0) - COALESCE(B.CreditBalance,0) AS Difference, 
-    coalesce(B.AccountID, A.GLsAccountID) as AccountID, +    COALESCE(B.AccountID, A.GLsAccountID) AS AccountID, 
-    (select max(EntryDateTime)  +    (SELECT MAX(EntryDateTime)  
-        from GL GL2  +        FROM GL GL2  
-        where GL2.AccountID = A.GLsAccountID +        WHERE GL2.AccountID = A.GLsAccountID 
-          and GL2.GLAccountID = 23) as LastGLCreditDate +          AND GL2.GLAccountID = 23) AS LastGLCreditDate 
-from+  
 +FROM
 ( (
-    select  coalesce(DivisionID, 10) as GLDivisionID,  +    SELECT  COALESCE(DivisionID, 10) AS GLDivisionID,  
-        AccountID as GLsAccountID,  +        AccountID AS GLsAccountID,  
-        -sum(Amount) as GLAmount +        -SUM(Amount) AS GLAmount 
-    from GL +    FROM GL 
-    where GLAccountID = 23 +    WHERE GLAccountID = 23 
-    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 AccountID, CompanyName, CreditBalance,  +    SELECT ID AS AccountID, CompanyName, CreditBalance,  
-         coalesce(DivisionID, 10) as OrderDivisionID +         COALESCE(DivisionID, 10) AS OrderDivisionID 
-    from Account +    FROM Account 
-    where CreditBalance > 0 +    WHERE CreditBalance > 0 
-as on A.GLsAccountID = B.AccountID +AS ON A.GLsAccountID = B.AccountID 
-where coalesce(A.GLAmount, 0)  coalesce(B.CreditBalance, 0) +  
-order by Division, CompanyName, GLsAccountID+WHERE COALESCE(A.GLAmount, 0) <> COALESCE(B.CreditBalance, 0) 
 +  
 +ORDER BY Division, CompanyName, GLsAccountID
 </code> </code>