EnjoySharePoint YouTube Channel

Case statement in SQL Server 2008

In this post, we will discuss how to use a case statement in SQL server 2008.

Get Office 365 Enterprise E3 Or Business Premium Subscription & Try out all the features

You can also check my previous posts on

asp.net MVC 4 tutorial

Forms Authentication in Asp.Net

Method Overloading in C#.Net.


CASE expression
WHEN expression1 THEN expression1
[[WHEN expression2 THEN expression2] […]]
[ELSE expressionN]

select Case Gender when 0 then ‘Male’ else ‘Female’ end as Gender from UserMaster where UserID=1

The above query will return Male of Gender field is 0 else it return Female.

Also Check below example where you can have multiple WHEN statements:

select SiteURL,SiteName =
WHEN 1 THEN ‘EnjoySharePoint.com’
WHEN 2 THEN ‘AspDotNetHelp.Com’
WHEN 3 THEN ‘Fewlines4Biju.com’
ELSE ‘No Site Available’
END from WebSite

Check out Best Alternative to InfoPath -> Try Now
You May Also like the Following SharePoint Tutorials:

About Bijay Kumar

I am Bijay from Odisha, India. Currently working in my own venture TSInfo Technologies in Bangalore, India. I am Microsoft Office Servers and Services (SharePoint) MVP (5 times). I works in SharePoint 2016/2013/2010, SharePoint Online Office 365 etc. Check out My MVP Profile.. I also run popular SharePoint web site SharePointSky.com

View all posts by Bijay Kumar →