PRB: Querying a DATETIME Value Without Quotes Gives Unexpected Results (268593)
The information in this article applies to:
- Microsoft SQL Server 2000 (all editions)
- Microsoft SQL Server 7.0
This article was previously published under Q268593 SYMPTOMS
Referring to datetime values without enclosing them in quotes does not cause an error. However, the results are not the same as if the value were enclosed in quotes.
CAUSE
According to SQL Server 7.0 Books Online, in the "Using Date and Time Data" topic, math functions can be directly used on a datetime field.
SQL Server recognizes date and time data enclosed in single quotation marks (') in these formats: - Alphabetic date formats (for example, 'April 15, 1998').
- Numeric date formats (for example, '4/15/1998', 'April 15, 1998').
- String formats that are not separated (for example, '19981207', 'December 12, 1998').
Therefore, a value without quotes that is used as a datetime value is treated as the default date plus the number of days equal to the computed amount of the assigned value. Numbers are rounded before they are added to the default date when necessary. For example, 12-1-2005 equates to the default date plus (12 minus 1 minus 2005) days. That equals January 1, 1900 plus (-1994 days). The final result is "1894-07-17 00:00:00.000".
RESOLUTION
If you follow the information in SQL Server Books Online you will not experience the problem described in this article.
Modification Type: | Major | Last Reviewed: | 10/16/2003 |
---|
Keywords: | kbprb KB268593 |
---|
|