SQL 2008 CASE statement aggravation...
Posted
by Brad
on Stack Overflow
See other posts from Stack Overflow
or by Brad
Published on 2010-05-07T17:34:37Z
Indexed on
2010/05/07
17:38 UTC
Read the original article
Hit count: 162
Why does this fail:
DECLARE @DATE VARCHAR(50) = 'dasf'
SELECT CASE WHEN ISDATE(@DATE) = 1 THEN CONVERT(date,@DATE) ELSE @DATE END
Msg 241, Level 16, State 1, Line 2 Conversion failed when converting date and/or time from character string.
Why is it trying to convert dasf to date when it clearly causes ISDATE(@DATE) = 1 to evaluate to false...
If I do:
SELECT ISDATE(@DATE)
The return value is 0.
© Stack Overflow or respective owner