>>And why would you use like with DateTime? Just for giggles? :-) Besides being invalid it'd also be much less efficient than using = given that like is a pattern matching operation.
>>
>>+++ Rick ---
>
>Invalid???? It is not. It is perfectly valid. And like is not a much less efficient operation than using =. An expression that has wildcard at the end only, utilizes the index.
>
>If your application is dealing a lot with date\datetimes then there is space to use it.
Huh? How would you have a LIKE operation on a DateTime work? Using like automatically will treat the date like a string?
If I have a date like this in the DB:
2015-06-01 11:52:59.057
and you do a query like this:
select * from wws_invoice where invdate like '2015-06-01%'
you get no match.
Unless I miss something here the only way you can get a valid date selection via string is by an exact match:
select * from wws_invoice where invdate = '2015-06-01 11:52:59.057'
The accepted way to do partial date queries is to use DatePart() in TSQL or you can use nasty code to CAST a date to a VARCHAR:
https://stackoverflow.com/questions/1629050/sql-server-datetime-like-select+++ Rick ---