August 22, 2008 at 8:45 am
I need to find a way to retrieve data for a 12 month time frame. I want this code to return data after a user enters one date (ex: 7/20/2008) for each month in succession of this data (ex: July, Aug, Sept...). The data returned should only be applicable for this 12 month time frame. I then want all this data populated in one table.
So far I have declared variables @ReportDate, @StartDate, @EndDate. In my table I have columns Start and End.
August 22, 2008 at 8:50 am
It is hard to say what the best way to do this without seeing the table and some data,
post the table def and some sample data and I am sure you will get some help..
August 22, 2008 at 10:27 am
I have attached a brief snapshot of table data. The goal tab reflects my ultimate goal. On that tab, I show only 2 months(Aug 08 and Sept08), but ultimately I want to show 12 months vertically (Aug 08...July 09) with corresponding prorations. Remember, I want the user to only enter one date (@ReportDate) which will equal column MyDate and build the rest thereafter.
August 22, 2008 at 6:48 pm
you can use datediff and use a while loop to loop thru 12 times to give you 12 months worth of data.
or you can use datediff and the BETWEEN function.
-----------------------------
www.cbtr.net
.: SQL Backup Admin Tool[/url] :.
August 28, 2008 at 7:04 am
use between @StartDate and @EndDate (reportdate and Enddate seem to be the same)
use dateadd to et @Startdate:
select @Startdate = dateadd(month,-12,@ReportDate)
The more you are prepared, the less you need it.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply