Case expression in SQL
Loading
Case expression in SQL
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Amit MohantyPosted Oct 30, 2022, 4:58 AM
The CASE expression returns a value on a specified condition when the first condition is met (like an if-then-else statement). So, once a condition is true, it will stop reading and return the result. If no conditions are true, it returns the value in the ELSE clause. If there is no ELSE part and no conditions are true, it returns NULL.
We can use a Case statement in select queries along with Where, Order By, and Group By clause. It can be used in the Insert statement as well.
Syntax:
CASE
WHEN condition1 THEN result1
WHEN condition2 THEN result2
WHEN conditionN THEN resultN
ELSE result
END;
For more details check the below links
https://www.w3schools.com/sql/sql_case.asp
https://www.sqlshack.com/case-statement-in-sql/
Yogeshkumar HadiyaPosted Oct 29, 2022, 4:03 PM
Not 100% sure what you are asking.
But if you are looking for how to use case in sql then these articles might helpful.
https://www.c-sharpcorner.com/article/case-statement-in-sql/
https://www.c-sharpcorner.com/UploadFile/3d39b4/case-statement-in-sql/