CASE expression in Sql Server | ASPMANTRA | Asp.Net,MVC,AngularJs,Jquery,Javascript,Sql Server AND WCF 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





Post a Comment

[blogger]

MKRdezign

Contact Form

Name

Email *

Message *

Powered by Blogger.
Javascript DisablePlease Enable Javascript To See All Widget