Equivalent of IF Statement in SQL Server


This content was proof-read by Grammarly. You can Try Grammary for FREE

There are times when you want to perform conditional checks within a SQL Query in SQL Server .

Below is a sample Query that demonstrates how to do it.

Equivalent of IF Statement in SQL Server

Assume that the Employee table contains a column called “Designation” and we might want to show a value 1 if the designation is SSE else show 0 . You can do it with the below query.

SELECT CASE
   WHEN designation ='SSE'
     THEN 1
     ELSE 0
   END as SENIOR, *
FROM Employee
Equivalent of IF Statement in SQL Server
Newsletter Signup

Subscribe to our weekly newsletter below and never miss the latest product or an exclusive offer.

Newsletter Signup

Subscribe to our weekly newsletter below and never miss the latest product or an exclusive offer.

%d bloggers like this: