Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Select Case

Author  Topic 

satheesh
Posting Yak Master

152 Posts

Posted - 2011-08-15 : 06:09:43
Dear all

I have a table quote with destination and trip fields.I need to select productname with some condition

Condition :-
If Destination is (AreaOne or AreaTwo ) and trip is 'single' then productname as EuropeExcess
If Destination is (AreaThree or Areafour ) and trip is 'Annual' then productname as WorldEXCESS
How to do this.Any help is highly appreciated.Many Thanks

Regards,
SG

Desired Result

Destination Trip Product

AreaOne Single EuropeExcess

AreaTwo Single EuropeExcess

AreaThree Annual WorldEXCESS

Devart
Posting Yak Master

102 Posts

Posted - 2011-08-15 : 07:05:45
Hi,

For example:

SELECT
...,
CASE WHEN Destination IN ('AreaOne','AreaTwo') AND Trip = 'single' THEN 'EuropeExcess'
WHEN Destination IN ('AreaThree','AreaFour') AND Trip = 'Annual' THEN 'WorldEXCESS' END AS ProductName
...
FROM
<your_table_name>


Devart,
SQL Server Tools:
dbForge Data Studio
dbForge Schema Compare
dbForge Data Compare
dbForge SQL Complete
Go to Top of Page

satheesh
Posting Yak Master

152 Posts

Posted - 2011-08-15 : 07:41:24
Thank You Devart.Its Working :-)
Go to Top of Page
   

- Advertisement -