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 |
|
gavakie
Posting Yak Master
221 Posts |
Posted - 2008-03-18 : 15:25:48
|
| Any suggestions on how I would find the 2nd and 4th tuesday of every month? |
|
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2008-03-18 : 16:35:12
|
quote: how I would find the 2nd and 4th tuesday of every month?
They should be right after the 2nd and 4th monday perhaps you can provide some more details like:- from when to when- is the desired output a single column of datetime values?- on inputs or tables you need to correlate?Be One with the OptimizerTG |
 |
|
|
gavakie
Posting Yak Master
221 Posts |
Posted - 2008-03-18 : 16:49:49
|
| Sorry I left that a little vague. I pretty much need it for this year and every year from now on. |
 |
|
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2008-03-18 : 16:55:23
|
quote: ...and every year from now on
still a little vaguesql will only support datetime values up to 12/31/9999. How would you like to deal with the billions of years that could follow?I know I'm being difficult but if you only need 5 years of dates it may make a difference to the solution.Be One with the OptimizerTG |
 |
|
|
gavakie
Posting Yak Master
221 Posts |
Posted - 2008-03-18 : 17:07:47
|
| Its for a report im building so im sure if I did just five years that would work and I could change it later on or put some type of year parameter on there. |
 |
|
|
LoztInSpace
Aged Yak Warrior
940 Posts |
Posted - 2008-03-18 : 20:30:35
|
| SELECT dateadd(day,7+(10-(datepart(dw,DATEADD(month, number, '20080301'))) )%7,DATEADD(month, number, '20080301')) as Tuesfrom master..spt_values m1where type='p'union allSELECT dateadd(day,21+(10-(datepart(dw,DATEADD(month, number, '20080301'))) )%7,DATEADD(month, number, '20080301'))from master..spt_values m1where type='p'You might want to stick it in a view or CTE so you can more easily ORDER BY - as it stands this will not come out in date order so don't complain it doesn't work! |
 |
|
|
|
|
|
|
|