Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
SQL Server 2008
»
SQL Server 2008 - General
»
Needing help capturing mon th end and...
Needing help capturing mon th end and transactions posted > month - 90
Rate Topic
Display Mode
Topic Options
Author
Message
headmanracer
headmanracer
Posted Wednesday, December 26, 2012 10:11 AM
Forum 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
Sean Lange
Sean Lange
Posted Wednesday, December 26, 2012 10:38 AM
SSCrazy Eights
Group: General Forum Members
Last Login: Yesterday @ 2:34 PM
Points: 8,592,
Visits: 8,233
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
Post #1400302
headmanracer
headmanracer
Posted Wednesday, December 26, 2012 11:30 AM
Forum 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
Sean Lange
Sean Lange
Posted Wednesday, December 26, 2012 12:08 PM
SSCrazy Eights
Group: General Forum Members
Last Login: Yesterday @ 2:34 PM
Points: 8,592,
Visits: 8,233
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
Post #1400324
« Prev Topic
|
Next Topic »
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.