October 6, 2006 at 4:06 am
Hi,
I am trying to pull out records from a table where the date is todays date. The date column recrods the date in this format: 06/10/2006 09:54:54
However, when I run my query which is somthing like the following:
SELECT * FROM Sales WHERE status = 8
AND (convert(varchar, ShipDate, 103) = convert(varchar,getdate(),103))
I used the convert to get rid of the time stamp but it still has not worked.
Can anyone tell me what I am doing wrong here?
Many thanks
Reet
October 6, 2006 at 4:38 am
`Try this
SELECT * FROM Sales WHERE status = 8
AND DATEADD(dd,DATEDIFF(dd,0,shipdate),0) = DATEADD(dd,DATEDIFF(dd,0,GETDATE()),0)
First check if status =8 is returning any rows without date filter.
Prasad Bhogadi
www.inforaise.com
October 6, 2006 at 4:52 am
Hi Prasad,
Your solution worked a treated.
Thank you very much for your help!
Cheers
Reet.
October 6, 2006 at 6:37 am
Just a note folks... anytime you use a column name in a formula in the WHERE or ON clause of a SELECT, you make it impossible for the coveted INDEX SEEK to occur. At best, you'll get an INDEX SCAN (about 51 times slower is what personal experience claims).
Although the code is a bit longer, a better way to do this is as follows...
AND shipdate >= DATEADD(dd,DATEDIFF(dd,0,GETDATE()),0)
--Jeff Moden
Change is inevitable... Change for the better is not.
October 6, 2006 at 9:12 am
Further information regarding the SARG issue can be found on this site, search for "Beware of Search Argument (SARG) Data Types"....
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply