Differences

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

Link to this comparison view

control_sql_-_query_to_breakdown_reconciliation_entries [2019/01/27 11:29]
127.0.0.1 external edit
control_sql_-_query_to_breakdown_reconciliation_entries [2019/02/05 11:40] (current)
admin
Line 1: Line 1:
-======  ====== 
- 
- 
- 
 ===== Explanation of SQL ===== ===== Explanation of SQL =====
  
Line 22: Line 18:
  
 <code sql> <code sql>
-declare @GLAccountID int+DECLARE @GLAccountID INT
-declare @StartDate datetime; +DECLARE @StartDate datetime; 
-Set @GLAccountID = 90; +  
-Set @StartDate = '7/30/2011'; +SET @GLAccountID = 90; 
-select from +SET @StartDate = '7/30/2011'; 
 +  
 +SELECT FROM 
 ( (
- select ID as ReconciliationID,  +    SELECT ID AS ReconciliationID,  
-   MONTH(StartDateTime) as StartMonth, DAY(StartDateTime) as StartDay, YEAR(StartDateTime) as StartYear,  +      MONTH(StartDateTime) AS StartMonth, DAY(StartDateTime) AS StartDay, YEAR(StartDateTime) AS StartYear,  
-   MONTH(EndDateTime) as EndMonth, DAY(EndDateTime) as EndDay, YEAR(EndDateTime) as EndYear,  +      MONTH(EndDateTime) AS EndMonth, DAY(EndDateTime) AS EndDay, YEAR(EndDateTime) AS EndYear,  
-   SummaryAmount as StartingBalance, +      SummaryAmount AS StartingBalance, 
-   DetailAmount as EndingBalance, +      DetailAmount AS EndingBalance, 
-   SummaryAmount - DetailAmount as ChangeInBalance, +      SummaryAmount - DetailAmount AS ChangeInBalance, 
-   UseActualTime as InProgress, +      UseActualTime AS InProgress, 
-   LinkID as GLAccount, +      LinkID AS GLAccount, 
-   (select AccountName from GLAccount where ID = LinkID) as AccountName, +      (SELECT AccountName FROM GLAccount WHERE ID = LinkID) AS AccountName, 
-   cast(BillingNotes as XML) as OtherCharges +      CAST(BillingNotes AS XML) AS OtherCharges 
- from Journal +    FROM Journal 
- where ClassTypeID = 9750 and EndDateTime > @StartDate +    WHERE ClassTypeID = 9750 AND EndDateTime > @StartDate 
- and LinkID = @GLAccountID+    AND LinkID = @GLAccountID
 )  Rs )  Rs
-full outer join+  
 +FULL OUTER JOIN 
 + 
 ( (
- select ReconciliationID, EntryDateTime,  +    SELECT ReconciliationID, EntryDateTime,  
-   case when Amount > 0 then Amount else end as Debit,  +      CASE WHEN Amount > 0 THEN Amount ELSE END AS Debit,  
-   case when Amount < 0 then -Amount else end as Credit,  +      CASE WHEN Amount < 0 THEN -Amount ELSE END AS Credit,  
-   Description, ReconciliationDateTime,  +      Description, ReconciliationDateTime,  
-   (select AccountName from GLAccount where ID = GLAccountID) as AccountName, +      (SELECT AccountName FROM GLAccount WHERE ID = GLAccountID) AS AccountName, 
-   SUM(case when Amount > 0 then Amount else endover (partition by ReconciliationID) as TotalDebit, +      SUM(CASE WHEN Amount > 0 THEN Amount ELSE ENDOVER (partition BY ReconciliationID) AS TotalDebit, 
-   SUM(case when Amount < 0 then -Amount else endover (partition by ReconciliationID) as TotalCredit, +      SUM(CASE WHEN Amount < 0 THEN -Amount ELSE ENDOVER (partition BY ReconciliationID) AS TotalCredit, 
-   SUM(Amount) over (partition by ReconciliationID) as BankChangeChange +      SUM(Amount) OVER (partition BY ReconciliationID) AS BankChangeChange 
- from GL +    FROM GL 
- where ReconciliationID is not NULL and ReconciliationDateTime > @StartDate +    WHERE ReconciliationID IS NOT NULL AND ReconciliationDateTime > @StartDate 
-   and GLAccountID = @GLAccountID +      AND GLAccountID = @GLAccountID 
-) GLs on Rs.ReconciliationID = GLs.ReconciliationID+) GLs ON Rs.ReconciliationID = GLs.ReconciliationID
    
-order by Rs.ReconciliationID desc,  SIGN(GLs.Debit), GLs.EntryDateTime+ORDER BY Rs.ReconciliationID DESC,  SIGN(GLs.Debit), GLs.EntryDateTime
 </code> </code>