Articles → SQL SERVER → Case statement in SQL server

Case statement in SQL server






What is the case statement?





Syntax


Case When <condition> then <value_to_be_returned_if_condition_is_satisfied> Else <value_to_be_returned_if_condition_is_not_satisfied> End



Example




Picture showing schema of Image table

Click to Enlarge



Picture showing data in Image table

Click to Enlarge



Select (Case When Photo is not Null then 'Exists' Else 'Not Exists' End) From [Image]




Picture showing output of case statement in SQL server

Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Tuesday, July 18, 2017

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250