SQL Server - IF...ELSE Statement
IF is conditional statement where it check boolean value that true or false.
By using IF..ELSE IF we can set the multiple if conditions like case statement. If condition get satisfied then if block get executed otherwise else part get execute.
Below is the syntax of IF..ELSE.
Syntax for IF..ELSE
In below example we are checking that if user is above 60 then select user type as senior citizen else select not senior citizen.
Note : If we have single statements in if..else block then no need to write the BEGIN and END block.
Below example indicate multiple if conditions in SQL Server. It also called as IF...ELSE IF... ELSE example.
We can also use multiple conditions in IF or ELSE IF statement.
Consider below result set and we have to find out that Vikrant and Jyo are belong from same city and class or not?
Note : We can concat multiple conditions using AND or OR operators.