Case expression in SQL
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Yogeshkumar HadiyaRank #358 · 7K reputationPosted Oct 29, 2022, 12:03 PM EDT
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/
Amit MohantyRank #112 · 20K reputationPosted Oct 30, 2022, 12:58 AM EDT
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/