sql - Strange behaviour in CASE expression using dateadd -


i'm expiriencing strange behaviour in sql statement using case. reproducable following example:

select     case     when 1=1         'foo'     when 1=2         (dateadd(s, 1435586700, '01/01/1970 00:00:00'))     when 1=3         (dateadd(s, 1435586700, '01/01/1970 00:00:00'))     else         'bar'     end result 

if execute on sql server 2008 returns no result. change second or third case succeed, returns value. if remove cases completely, works fine.

at first thought problem dateadd being executed in case , failing because of passed parameter values. in example constant , should work in case.

what going on here?

case expression type determined @ compile-time. however, values not evaluated until run-time.

by rules of type-conversion, think expression return datetime. results in error 'foo' , 'bar' values -- when when conditions met.


Comments

Popular posts from this blog

android - Pass an Serializable object in AIDL -

How to provide Authorization & Authentication using Asp.net, C#? -

How to use Authorization & Authentication in Asp.net, C#? -