Equivalent of IF Statement in SQL Server

Published on December 12, 2013 by abundantcode

Filed under SQL Server

Last modified December 12, 2013

Print this page

rate 1 star rate 2 star rate 3 star rate 4 star rate 5 star
Your rating: none, Average: 0 (0 votes)

This article have been viewed 3251 times

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

If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

Leave a Comment


x

You might be Interested in these Posts

How to Perform Inner Join using LINQ in C# ?

Are you looking for the syntax on how to perform inner join using LINQ in C# ? . Below is a sample c...

How to Update From Select Statement in SQL Server ?

Below is a sample query that demonstrates how to update a table by getting the data from the select ...

Best Java Equivalent for LINQ (C#)

LINQ Query and Lambda expressions are one of the popular features of C# which helped the .NET develo...