Case in sql server

Using CASE In sql

Case is very useful concept in sql. It makes query very efficient and easy. It reduce the line of code of that query. It makes the query more Readable.
Syntax for case is :

 Select ,

  Case

  Then 

else

End

Now Let us try an example
create table Item
(

Itemname varchar(50),
Price numeric(5,2)

)

 

 insert into Item(Itemname , Price)values('apple',60);
 insert into Item(Itemname , Price)values('Orange',150);
 insert into Item(Itemname , Price)values('banana',10);
 insert into Item(Itemname , Price)values('pine apple',60);

 Select Itemname,Category =

    Case  
    when  (Price> 100.00) Then 'Expensive'

   when  (50.00<=Price AND Price<=100.00) Then 'Moderate'

   When  (Price< 20) Then  'Inexpensive'

   else  'Unknown'
   end
From Item




drop table Item