SQL datetime LIKE select - why do I need an extra %?
Posted
by
tomsullivan1989
on Stack Overflow
See other posts from Stack Overflow
or by tomsullivan1989
Published on 2013-11-07T09:40:02Z
Indexed on
2013/11/07
9:53 UTC
Read the original article
Hit count: 208
Can someone explain to me why when I perform a LIKE
select in SQL (T-SQL) on a varchar
column I can do the following:
SELECT *
FROM Table
WHERE Name LIKE 'Th%'
to get names beginning with Th
, but when I do the same on a datetime
column I need a %
before the year, like:
SELECT *
FROM Table
WHERE Date LIKE '%2013%'
to get dates in 2013. The datetimes are stored in yyyy-MM-dd hh:mm:ss
format. I know I could use a DATEPART
style query but I was just interested in why I need the extra %
here.
© Stack Overflow or respective owner