Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Needing help capturing mon th end and transactions posted > month - 90 Expand / Collapse
Author
Message
Posted Wednesday, December 26, 2012 10:11 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, December 26, 2012 1:13 PM
Points: 2, Visits: 4
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.
Post #1400294
Posted Wednesday, December 26, 2012 10:38 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 3:28 PM
Points: 13,103, Visits: 11,933
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 Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Post #1400302
Posted Wednesday, December 26, 2012 11:30 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, December 26, 2012 1:13 PM
Points: 2, Visits: 4
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
Post #1400313
Posted Wednesday, December 26, 2012 12:08 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 3:28 PM
Points: 13,103, Visits: 11,933
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 Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Post #1400324
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse