SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


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


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

Author
Message
headmanracer
headmanracer
Forum Newbie
Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)

Group: General Forum Members
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.
Sean Lange
Sean Lange
SSC Guru
SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)

Group: General Forum Members
Points: 62691 Visits: 17959
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.

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)
headmanracer
headmanracer
Forum Newbie
Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)

Group: General Forum Members
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
Sean Lange
Sean Lange
SSC Guru
SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)SSC Guru (62K reputation)

Group: General Forum Members
Points: 62691 Visits: 17959
That looks like Oracle not SQL Server. SQL Server doesn't have a TO_CHAR function. :-P

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.

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)
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search