Quantcast
Viewing latest article 4
Browse Latest Browse All 4

ELSE IF vs. just plain ELSE

I just want to verify some observations I've made. I was debugging some T-SQL that was more or less like this:

IF <Condition1> 

SQLStatement1

ELSE IF <Condition2>

SQLStatement2

The thing is, I was only experiencing the bug when BOTH conditions were true. Both sets of statements were running. When I changed "ELSE IF <Condition2>" to just plain "ELSE" my problem was solved.

This was surprising to me, because I had expected that the ELSE IF would not execute at all in cases when IF evaluated to true. In my case, I don't need the second condition at all, but what if I wanted a series ELSE IF statements? I would have expected statements to run only on the first true condition. It appears that's not the case. Or am I misunderstanding?

Thanks!


Viewing latest article 4
Browse Latest Browse All 4

Trending Articles



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