Quantcast
Viewing latest article 6
Browse Latest Browse All 19

IF ELSE vs CASE WHEN

Neil.W,

(Just a guess) Both of these statement lies under T-SQL section. "If" is a part of procedural level programming that is enabled in SQL by MSft. Whenever you are using an "If" statement (as you know it is object based not set based), it looks for the given condition to be true or false nothing else. Whereas when you are using a "CASE" statement, it is a set based syntax, thus it'll look for the return type of that function to match with the other replaceable, that is  "0" in your case.

I suppose you already know that all the data types in a case statement should be same or should be available for implicit conversion by the SQL engine.

Thus in your problem statement when Engine starts searching the function "myfunc()" for its return type it does not finds anything, that depicts it can never match the data type of "0"(INT) to that of the return type of function.

Only problem here which I see is that MSft should come with proper error statement in this case. Instead of "Cannot find either column "dbo" or the user-defined function or aggregate "dbo.myfunc", or the name is ambiguous."  it should say something like "Implicit conversion failed since function does not exist"


Please use Marked as Answer if my post solved your problem and use Vote As Helpful if a post was useful.


Viewing latest article 6
Browse Latest Browse All 19

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>