mo.notono.us

Wednesday, May 25, 2005

SQL: More smalldatetime surprises

Earlier I mentioned some unexpected behavior with ISDATE(@foo) and CAST(@foo AS smalldatetime). This time the surprise came when looking at some existing code that compared a date to an empty string, expecting that @Date <> '' would yield false if the date had been set. Not so fast:

DECLARE @Date1 smalldatetime, @Date2 smalldatetime
SELECT @Date1 = '1/1/1900', @Date2 = ''
IF @Date1 = @Date2 
  PRINT 'funny'
ELSE 
  PRINT 'expected'
Results: funny << Statement Executed Successfully >>

Labels:

1 Comments:

Post a Comment

<< Home