[thelist] Using Wildcards and Dates in SQL Server

Jason Handby jasonh at pavilion.co.uk
Tue Jun 17 12:01:05 CDT 2003

> Why doesn't this return anything? (SQL Server 2000, IIS5, Win2K)
>   SELECT * FROM curEvents WHERE eDate LIKE '6/%/2003'
> I thought the % character worked as a wildcard -- am I missing
> something?

This works by implicitly converting the date to a string, and so it will
only match if your string and the converted date are of the same format.
Given the vagaries of date to string conversion and formatting, and the
overhead involved in any case, I wouldn't do it that way.

> There's got to be a million ways to get the current month's events out
> of this table. Anyone want to suggest a better one?


  SELECT * FROM curEvents
	AND DATEPART(yyyy, eDate) = DATEPART(yyyy, GETDATE())


More information about the thelist mailing list