Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FORECAST DATES

Status
Not open for further replies.

dellguy

Programmer
Aug 14, 2001
70
CA
I need to create a SELECT statement that provides a list of month-end dates from a particular start date to end date.

Any ideas? Any help would be greatly appreciated.
 
Try this. This will get you all of the month ends from 2010 through 2012. Just change the values to get other dates.
Code:
DECLARE @StartDate DATETIME
DECLARE @EndDate DATETIME
SELECT @StartDate = '20100101'
SELECT @EndDate = '20121231'

SELECT DISTINCT DATEADD(day, -1, DATEADD(month, [number], CONVERT(DATETIME, '19000201'))) 
AS MonthEnd
FROM master.dbo.spt_values 
WHERE ([number] BETWEEN 0 AND 2000)
AND (@StartDate <= DATEADD(day, -1, DATEADD(month, [number], CONVERT(DATETIME, '19000201')))  AND @EndDate >= DATEADD(day, -1, DATEADD(month, [number], CONVERT(DATETIME, '19000201'))) )
ORDER BY DATEADD(day, -1, DATEADD(month, [number], CONVERT(DATETIME, '19000201')))
 

Thanks RiverGuy!!

Would you happen to know the Oracle equivilent as well ?
I need both... :eek:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top