SQL Server - CASE Statement
CASE Statement in SQL Server is similar to SWITCH CASE in C# or other object oriented programing language.
Note : When we use CASE Statement in SQL Server?
To avoid multiple if condition we use the CASE Statement.
We can't use the if condition in select statement where we can use the CASE statement.
We always use select statement while writing CASE statement. CASE statement always end with END keyword.
Syntax for CASE Statement
Below is the example of multiple CASE statement.
Note : We always use th CASE statement with SELECT statement.
CASE statement example with table columns.
Consider below result set and we have to categorize the student in three part
1) Marks less than 35 then Fail
2) Marks between 35 to 60 then Second Class
3) Marks between 61 to 100 then First Class
Note : CASE statement always return only one value.