Reputation: 5044
hey guys, i have created a stored procedure, wherein i have datetime field in the select query. here is what my query is
select * from tablename where publishdate like '%03/10/2011%'
is this possible, or how should i form a query my objective is query should return the records for 10-March-2011
Upvotes: 0
Views: 4514
Reputation: 24498
The best method for doing this is:
Select *
from tablename
Where publishdate >= '20110310'
and publishdate < '20110311'
By separating the conditions like this, you are allowing SQL Server to use an index on the publishdate column (if an index exists). The query I show would use a super-fast index seek instead of a scan, resulting in far better performance.
Upvotes: 0
Reputation: 6637
Try
select * from tablename where day(publishdate) = 10 And Month(publishdate) = 3
And Year(publishdate) = 2011 --Let the required date be 10th March 2011
Hope this help.
Upvotes: 0