Tutorial by Examples

Like most of the other programming languages, T-SQL also supports IF..ELSE statements. For example in the example below 1 = 1 is the expression, which evaluates to True and the control enters the BEGIN..END block and the Print statement prints the string 'One is equal to One' IF ( 1 = 1) --<-...
We can use multiple IF statement to check multiple expressions totally independent from each other. In the example below, each IF statement's expression is evaluated and if it is true the code inside the BEGIN...END block is executed. In this particular example, the First and Third expressions are ...
In a single IF..ELSE statement, if the expression evaluates to True in the IF statement the control enters the first BEGIN..END block and only the code inside that block gets executed , Else block is simply ignored. On the other hand if the expression evaluates to False the ELSE BEGIN..END block ge...
If we have Multiple IF...ELSE IF statements but we also want also want to execute some piece of code if none of expressions are evaluated to True , then we can simple add a final ELSE block which only gets executed if none of the IF or ELSE IF expressions are evaluated to true. In the example below...
More often than not we need to check multiple expressions and take specific actions based on those expressions. This situation is handled using multiple IF...ELSE IF statements. In this example all the expressions are evaluated from top to bottom. As soon as an expression evaluates to true, the cod...

Page 1 of 1