tags:

views:

62

answers:

4

hi guys, I have a field named 'CreatedDate' in table.It contain value as 2009-12-07 11:02:20.890.My search parameter is createddate.Parameter contains value as 2009-12-07.My parameter contains only datepart.If my parameter contains only 2009-12-07 its not giving result.Only when time is included its giving result. My query is Select * from STD_Enquiry where CreatedDate='2009-12-07 Can anybody give approppriate query to get the result?

+4  A: 

Compare only on the date portion (without time):

WHERE DateColumn >= DATEADD(day, DATEDIFF(day, 0, @SomeDateParam), 0)
Mitch Wheat
Yes. But if you include an explanation (or a link to one) on *why* this works, it'd help him more.
Philip Kelley
@Phillip, ok thanks: http://mitch-wheat.blogspot.com/2007/05/sql-server-compare-date-part-of.html
Mitch Wheat
And this too: http://stackoverflow.com/questions/133081/most-efficient-way-in-sql-server-to-get-date-from-datetime
gbn
@gn: nice ref. to timings of the techniques.
Mitch Wheat
A: 

Try this:

Select * from STD_Enquiry where CreatedDate like '2009-12-07%'
Dumb Guy
that is not the way I'd recommend!
Mitch Wheat
A: 

Use this query to comapare only date

Select * from STD_Enquiry where to_char(CreatedDate,'mmddyyyy') = '09102007'
Vijay Sarathi
A: 

Select * from Table where CreatedDate= ''Datepart(yyyy, CreatedDate) + '-' + Datepart(mm,CreatedDate) + '-' + Datepart(DD,CreatedDate)''

MSH