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 |
|
macca
Posting Yak Master
146 Posts |
Posted - 2005-08-15 : 10:05:27
|
| I've got a sql query in which I compare the date in a field (called RecordDate) to todays date (got using GETDATE function). I want the query only to apply to records where their RecordDate is 10 days less than todays date.I want to know what the where clause should e.g.Select *.........WHERE RecordDate = GETDATE + 10Anyone know what the WHERE Clause should be.macca |
|
|
Kristen
Test
22859 Posts |
Posted - 2005-08-15 : 10:33:57
|
| Select *.........WHERE DATEDIFF(Day, RecordDate, GETDATE()) = 10However, watch out for where RecordDate contains a time - and the fact that GetDate() will include a timeKristen |
 |
|
|
macca
Posting Yak Master
146 Posts |
Posted - 2005-08-15 : 10:54:44
|
| Thanks Kristen,That worked!macca |
 |
|
|
Page47
Master Smack Fu Yak Hacker
2878 Posts |
Posted - 2005-08-15 : 13:20:49
|
| If you have an index on RecordDate that you want to take advantage of you'll need to stand on it's own in the predicate.where RecordDate >= dateadd(dd,datediff(dd,0,getdate()-10),0) andRecordDate < dateadd(dd,datediff(dd,0,getdate-9),0)Jay White |
 |
|
|
|
|
|