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)
|
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:
No comments:
Post a Comment