Re: SQL bug, ISNULL function with smalldatetime
From: oj (nospam_ojngo_at_home.com)
Date: 02/10/05
- Next message: Nab: "Re: Object reference not set to an instance of an object."
- Previous message: Hugo Kornelis: "Re: Comparing DATE with TIMESTAMP fields possible ?"
- In reply to: Hugo Kornelis: "Re: SQL bug, ISNULL function with smalldatetime"
- Next in thread: oj: "Re: SQL bug, ISNULL function with smalldatetime"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 9 Feb 2005 16:06:43 -0800
>>WHERE 2005-02-10T00:54:00.000 >= 2005-02-10T00:54:17.123
Ah, didn't even think about the rounding and re-implicit conversion to
datetime. Tks.
-- -oj "Hugo Kornelis" <hugo@pe_NO_rFact.in_SPAM_fo> wrote in message news:gh8l0151vkpi557b6nigvl2npok6sa95v7@4ax.com... > On Wed, 9 Feb 2005 15:21:04 -0800, shovem wrote: > >>My version is >> >>Microsoft SQL Server 2000 - 8.00.760 (Intel X86) Dec 17 2002 14:22:05 >>Copyright (c) 1988-2003 Microsoft Corporation Developer Edition on >>Windows >>NT 5.1 (Build 2600: Service Pack 2) >> >>For @dateParam, I'm setting it to getUTCDate() >>I forgot to include that code: >> >>DECLARE @dateParam datetime >>SET @dateParam = getUTCDate() > > Hi shovem, > > This is not a bug, but working as designed. > > From Books Online, section on ISNULL: > > Return Types > Returns the same type as check_expression. > > (note that this is an important -and often unexpected!- differnece between > ISNULL and COALESCE) > > So ISNULL(tdq.test, @dateParam) will return a smalldatetime. If tdq.test > is NULL and @dateParam is 2005-02-10T00:54:17.123, it will be converted to > smalldatetime, rounded to the nearest full minute: 2005-02-10T00:54. > > The complete WHERE clause reads > WHERE ISNULL(tdq.test, @dateParam) >= @dateParam > Here, a smalldatetime (the result of ISNULL) is compared to a datetime > (@dateParam). Rules of datatype precedence say that the smalldatetime has > to be converted to datetime. Of course, the seconds that were lost during > the previous conversion won't return, so the final comparison is > WHERE 2005-02-10T00:54:00.000 >= 2005-02-10T00:54:17.123 > And this, of course, evaluates to false - therefor, the row is not > returned. > > The fix is simple: either declare the parameter as smalldatetime, or > create the column as datetime. And if either of these solutions is not > possible, then use explicit casting instead of relying on implicit > conversions. > > Best, Hugo > -- > > (Remove _NO_ and _SPAM_ to get my e-mail address)
- Next message: Nab: "Re: Object reference not set to an instance of an object."
- Previous message: Hugo Kornelis: "Re: Comparing DATE with TIMESTAMP fields possible ?"
- In reply to: Hugo Kornelis: "Re: SQL bug, ISNULL function with smalldatetime"
- Next in thread: oj: "Re: SQL bug, ISNULL function with smalldatetime"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|
|