Needing help capturing mon th end and transactions posted > month - 90

  • I need some help with SQL to capture transactions posted 90 days prior to month end for the last 12 months. I have a table named TRANSACTIONS and a field named TRANSACTIONS.POST_DATE and also a calendar table named VOCAB.DATE_MM_DD_YYYY where these are joined based on TRANSACTIONS.POST_DATE = VOCAB.DATE_MM_DD_YYYY.

    For example where the month end is 11/30/2012 I need to sum transactions posted 9/2/2012 - 11/30/2012 (90 days) and where month end is 10/31/2012 I need to sum transactions posted 8/3/2012 - 10/31/2012 (90 days). I need this for a rolling 12 months, and I need to automate this query.

    Thanks in advance.

  • headmanracer (12/26/2012)


    I need some help with SQL to capture transactions posted 90 days prior to month end for the last 12 months. I have a table named TRANSACTIONS and a field named TRANSACTIONS.POST_DATE and also a calendar table named VOCAB.DATE_MM_DD_YYYY where these are joined based on TRANSACTIONS.POST_DATE = VOCAB.DATE_MM_DD_YYYY.

    For example where the month end is 11/30/2012 I need to sum transactions posted 9/2/2012 - 11/30/2012 (90 days) and where month end is 10/31/2012 I need to sum transactions posted 8/3/2012 - 10/31/2012 (90 days). I need this for a rolling 12 months, and I need to automate this query.

    Thanks in advance.

    Hi and welcome to SSC. It is impossible to provide any assistance based on what you have posted. There just simply are not enough details. You need to provide ddl (create table statements), sample data (insert statements) and desired output based on your sample data.

    Take a look at the first link in my signature for best practices when posting questions.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

  • I have written some simple SQL that returns results for the last mon th results. I need this same data for a rolling 12 months and an example of what I want returned. Again thanks for any help.

    SQL:

    SELECT SUM (TRANSACTIONS.TX_AMOUNT)

    FROM CLARITY_REPORT.TRANSACTIONS TRANSACTIONS

    INNER JOIN

    VOCAB.CALENDAR_FULL CALENDAR_FULL

    ON (TO_CHAR (TRANSACTIONS.TX_POST_DATE, 'MM/DD/YYYY') =

    TO_CHAR (CALENDAR_FULL.DATE_MM_DD_YYYY, 'MM/DD/YYYY'))

    WHERE (TRANSACTIONS.TX_POST_DATE >= CALENDAR_FULL.END_DT - 89

    AND TRANSACTIONS.TX_POST_DATE <= CALENDAR_FULL.END_DT)

    Desired Results:

    END_DT 90_DAY_TRANSACTION_AMOUNT

    12/31/2011 $60,742,554.35

    1/31/2012 $121,460,890.56

    2/29/2012 $179,787,261.67

    3/31/2012 $184,373,935.77

    4/30/2012 $184,040,522.60

    5/31/2012 $182,352,585.11

    6/30/2012 $180,535,772.74

    7/31/2012 $179,692,597.87

    8/31/2012 $185,108,106.00

    9/30/2012 $188,808,278.08

    10/31/2012 $196,545,546.09

    11/30/2012 $197,238,207.00

  • That looks like Oracle not SQL Server. SQL Server doesn't have a TO_CHAR function. 😛

    I am willing to help you but you have to provide enough details for me to have a chance. As I said in my last post you need to provide ddl and sample data. You have provided what you want for output.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply