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.
Author |
Topic |
Humate
Posting Yak Master
101 Posts |
Posted - 2010-08-10 : 11:45:47
|
Hi AllI 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 B07/02/2010 31/12/2010Would show following results:07/02/201007/05/201007/08/201007/11/2010Can 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 < 4JimEveryday I learn something that somebody else already knew |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
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 @SampleSELECT 10012, '2010-01-22 00:00:00.000', '2010-12-31 00:00:00.000' UNION ALLSELECT 10013, '2010-03-05 00:00:00.000', '2010-12-31 00:00:00.000' |
 |
|
Humate
Posting Yak Master
101 Posts |
Posted - 2010-08-10 : 17:05:18
|
Now solved, I used a values table like jimf. Thanks both. |
 |
|
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 MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|
|