Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Creating data for a date range quarterly

Author  Topic 

Humate
Posting Yak Master

101 Posts

Posted - 2010-08-10 : 11:45:47
Hi All

I have two dates in my table, I would like to select from this table and create a list of each 3 month anniversary inside the time period.

So date range like this:

Column A Column B
07/02/2010 31/12/2010

Would show following results:

07/02/2010
07/05/2010
07/08/2010
07/11/2010

Can anyone help? I'm sure I should know this

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2010-08-10 : 12:53:29
select dateadd(month,spt.number*3,'02/07/2010'),spt.number
from master..spt_values spt
where spt.type = 'P' and number < 4


Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-08-10 : 13:42:54
see below

http://visakhm.blogspot.com/2010/02/generating-calendar-table.html

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Humate
Posting Yak Master

101 Posts

Posted - 2010-08-10 : 16:26:00
Not sure I follow the example, could you elaborate with my sample please?

DECLARE @Sample TABLE
(
RecordID INT,
StartDate DATETIME,
EndDate DATETIME
)

INSERT @Sample
SELECT 10012, '2010-01-22 00:00:00.000', '2010-12-31 00:00:00.000' UNION ALL
SELECT 10013, '2010-03-05 00:00:00.000', '2010-12-31 00:00:00.000'
Go to Top of Page

Humate
Posting Yak Master

101 Posts

Posted - 2010-08-10 : 17:05:18
Now solved, I used a values table like jimf. Thanks both.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-08-11 : 10:39:36
quote:
Originally posted by Humate

Now solved, I used a values table like jimf. Thanks both.


that has limitation when you've to generate large date range

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -