SQL SERVER - SQL CASE Expression
SQL
CASE Expression
When the first condition is met, the CASE expression returns a value. Once
a condition is true, it will stop reading and return the result. The value is
returned if no conditions are true.
Syntax :
CASE
WHEN condition1 THEN result1
WHEN condition2 THEN result2
WHEN conditionN THEN resultN
ELSE result
END;
Example
:
SELECT Emp_Id, Salary,
CASE
WHEN Salary > 30000 THEN 'The Salary
is greater than 30K'
WHEN Salary = 30000 THEN 'The
Salary is 30K'
ELSE 'The Salary is under 30K'
END AS Saltxt
FROM Employees;
No comments:
Post a Comment