Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
what is the most efficient way of comparing a column with a dateFor example , I want to compare update_date with getdate()-5 i can do in this way .convert ( varchar, update_date, 112) = convert ( varchar, getdate()-5, 112) or i can use greater than and less than the update_date...But this doesnt look as effient.Can any one suggest a tested way of comparing date values?Chandragupta MouryaTakhyashila
Lamprey
Master Smack Fu Yak Hacker
4614 Posts
Posted - 2010-08-03 : 13:09:34
Try soemthing like:
WHERE update_date >= DATEADD(DAY, DATEDIFF(DAY, 0, GETDATE()), -5) AND update_date < DATEADD(DAY, DATEDIFF(DAY, 0, GETDATE()), -4)
konark
Yak Posting Veteran
60 Posts
Posted - 2010-08-03 : 15:37:02
Well this is also i have tried.. Any other ways guys ?Chandragupta MouryaTakhyashila
Lamprey
Master Smack Fu Yak Hacker
4614 Posts
Posted - 2010-08-03 : 16:50:18
You said, "what is the most efficient way of comparing a column with a date?" Do you want something else? Or do you have some requirement such that you cannot use the method I provided?
konark
Yak Posting Veteran
60 Posts
Posted - 2010-08-03 : 19:39:53
The one you mentioned is also taking a lot of time...Chandragupta MouryaTakhyashila