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: sql
1 Comments:
btw - if @Date2 = 0, we'd get the same result...
By Oskar Austegard, at Friday, June 10, 2005 11:22:00 AM
Post a Comment
<< Home