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 >>
posted by Oskar Austegard at 12:38 PM on May 25, 2005
"SQL: More smalldatetime surprises"
1 Comment -
btw - if @Date2 = 0, we'd get the same result...
Friday, June 10, 2005 11:22:00 AM