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 |
|
omega1983
Starting Member
40 Posts |
Posted - 2009-11-20 : 13:21:45
|
| I have a portion of code:select ID,Namewhere gifteffdat >='2009-10-01' and gifteffdat <='2009-10-30'from giftsNow I need a way of showing records each month as long as thet fall within a calendar month. I need to get away from hardcoding the month rangeI need something like if the gifteffdat falls within the first and last day of the currentmonth, show the records |
|
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2009-11-20 : 13:58:51
|
| [code]where datediff(month, gifteffdat, getdate()) = 0 --current monthwhere datediff(month, gifteffdat, getdate()) = 1 --previous month[/code]Be One with the OptimizerTG |
 |
|
|
omega1983
Starting Member
40 Posts |
Posted - 2009-11-20 : 14:23:33
|
Thank you very much it workedquote: Originally posted by TG
where datediff(month, gifteffdat, getdate()) = 0 --current monthwhere datediff(month, gifteffdat, getdate()) = 1 --previous month Be One with the OptimizerTG
|
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2009-11-20 : 15:21:06
|
quote: Originally posted by X002548 Yes and it will do a table or index scanBrett
That's true. If the column has an index this may be better:--current monthwhere gifteffdat > dateadd(month, datediff(month, 0, getdate()), 0)and gifteffdat <= dateadd(month, datediff(month, 0, getdate()), 1) Be One with the OptimizerTG |
 |
|
|
|
|
|
|
|