CASE expression in Sql Server - Free Asp.Net,MVC,AngularJs,Jquery,Javascript,Sql Server,WCF,Entity framework snippets and tutorial


CASE expression in Sql Server

In this article I am going to explain about Sql Server’s CASE expression.

Description:
Case statement is also known as CASE expression. We can use CASE expression anywhere in Sql query. It can be used with in select, where clauses, Order by clause, HAVING clauses, insert, update and delete statements.
Simple case expression Example:
Syntax:
CASE expression
   WHEN value_1 THEN result_1
  [...n]
END

I have created a table CountryCode and insert some dummy record into it.

CountryId
int
CountryCode
varchar(50)

CASE expression in Sql Server


Select CountryCode,
case
when CountryCode='IN' then 'India'
when CountryCode='US' then 'United States of America'
when CountryCode='CU' then 'Cuba'
when CountryCode='GB' then 'United Kingdom'
end as [Country Name]
from CountryCode

Output:

CASE expression in Sql Server





What do you think about this article?

If you found this article useful, please share and follow on Facebook, Twitter, Google Plus and other social media websites. To get free updates subscribe to newsletter. Please put your thoughts and feedback in comments section.

Share this

Share on FacebookTweet on TwitterPlus on Google+
loading...


EmoticonEmoticon