PRB: Information About Use of LIKE Operator to Convert String to Datetime Query (284997)
The information in this article applies to:
- Microsoft SQL Server 2000 (all editions)
- Microsoft SQL Server 7.0
This article was previously published under Q284997 SYMPTOMS
When the day of the month is a single digit, an invalid input string format in a query, which uses the LIKE operator with a wildcard character %, may lead to unexpected results.
CAUSE
When you use the LIKE operator with a wildcard character (%), SQL Server first converts the specified date (enclosed in the single quotation marks) to a datetime format, and then converts the date to a varchar string. When converting the date enclosed in the single quotation marks along with wildcard character (%) to a datetime format, SQL Server rejects all values that it cannot recognize as a date. When the day of the month is a single digit, if you do not place two spaces between the month and the day, SQL Server does not recognize the value as a valid datetime format, which may therefore lead to unexpected results.
WORKAROUND
Make sure that there are two spaces between the month and the day as in this example:
'Jan 3 2001%'
Modification Type: | Major | Last Reviewed: | 10/16/2003 |
---|
Keywords: | kbprb KB284997 |
---|
|