Quantcast
Channel: IF ELSE vs CASE WHEN
Browsing latest articles
Browse All 19 View Live

IF ELSE vs CASE WHEN

Hi George,But this is not a stored procedure.  They are just 2 statements: IF...ELSE construct and SELECT statement with CASE expression.No matter how you slice it, logically they should be consistent....

View Article


IF ELSE vs CASE WHEN

Kalman,Think of it this way....  There are compile time errors and there are run-time errors.  Syntactically, there is nothing wrong with:if exists(select name from sysobjects where name = 'myfunc')...

View Article


IF ELSE vs CASE WHEN

It's an interesting topic.  There' still more to it, though, and the IF statement definitely causes certain types of errors not to be detected under certain conditions (syntax always has to be valid...

View Article

IF ELSE vs CASE WHEN

This sounds like the most plausible explanation.

View Article

IF ELSE vs CASE WHEN

If the function does not exist, SQL cannot determine the return data type, and therefore throws the error.  You should realize that the query engine makes this determination before the code is actually...

View Article


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...

View Article

IF ELSE vs CASE WHEN

That's a great explanation and article, it's very accurate and true.  I think it's a different topic though, because mixing data types in a Case statement yields the error message (in this case)...

View Article

IF ELSE vs CASE WHEN

The explanation is this...SQL Server will always return the same data type regardless of which branch of the case/when expression is actually returned.  In your case, one branch has a function call so...

View Article


IF ELSE vs CASE WHEN

And to add a bit... It syntax checks, but doesn't execute the SQL, when the interpreter processes the Transact SQL, but an IF statement causes a line or block not to execute.Examples:if 1 = 2...

View Article


IF ELSE vs CASE WHEN

See this blog postSQL Server Case/When Data Type problemsIt explains that even if the code is not supposed to be executed, it still executes.For every expert, there is an equal and opposite expert. -...

View Article

IF ELSE vs CASE WHEN

The only explanation I can think of that 2 different project teams programmed it during the years.There is no T-SQL theoretical explanation for it.if exists(select name from sysobjects where name =...

View Article

IF ELSE vs CASE WHEN

Number 1 is TRANSACT-SQL, running as a programming layer, and the flow of control determines what statements (including what SQL statements) get sent to the database engine.  In number 1's case, the...

View Article

IF ELSE vs CASE WHEN

Right - but the first condition fails so theoretically it should not try to execute the UDF.

View Article


IF ELSE vs CASE WHEN

Thanks - but you are missing the point of the question. Assuming myfunc does not exist, why does the first statement work, but the second statement fails?

View Article

IF ELSE vs CASE WHEN

You should be able to find the information from the definition. http://msdn.microsoft.com/en-us/library/ms181765.aspxYou cannot use CASE as a Flow Control method and the CASE eveluates its expression...

View Article


IF ELSE vs CASE WHEN

You have not created any function with a name dbo.myfunc(). Create the function, it will resolve your error. create FUNCTION dbo.myfunc() RETURNS int  AS  BEGIN       RETURN 100 END; select case when...

View Article

IF ELSE vs CASE WHEN

you might want to add a "select" before that .. as the sql engine expects for a value in that particular position. When you have it as a subquery - the value is provided .. select case when...

View Article


IF ELSE vs CASE WHEN

For CASE expressions all expressions should be of the same type or implicitly convertible types. Therefore I suspect it attempts to call this function in order to find out the return type.For every...

View Article

IF ELSE vs CASE WHEN

Can someone explain why the first statement works, but the second one generates an error if myfunc() does not exist? 1) if exists(select name from sysobjects where name = 'myfunc') select...

View Article
Browsing latest articles
Browse All 19 View Live


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