sql - datetime variable versus string representation of datetime variable
Posted
by BhejaFry
on Stack Overflow
See other posts from Stack Overflow
or by BhejaFry
Published on 2010-05-06T03:52:44Z
Indexed on
2010/05/06
3:58 UTC
Read the original article
Hit count: 485
Hi folks,
I have a query that takes too long to respond when the search parameter happens to be a varchar datatype with date. However, if i convert varchar to datetime variable, the query runs fine.
For ex:
This takes too long.
select count(id) from names where updateddate > '1/5/2010'
This runs fine.
declare @dateparam datetime
set @dateparam = convert(datetime, '1/5/2010',102)
select count(id) from names where updateddate > @dateparam
What's the reason one runs fine but the other doesn't?
TIA
© Stack Overflow or respective owner