Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

CASE syntax

Posted on 2009-07-09
2
Medium Priority
?
180 Views
Last Modified: 2012-05-07
I cannot get a right syntax for a simple case statement.
I am trying:
Select CASE myfield
when ('val1' or 'val2' or 'val3') THEN 'A'
when ('val4' or 'val5') THEN 'B'
else 'C'

I am getting a syntax error

I also tried to replaced OR with , but no success.

Could you help with the syntax when the case statement has more than one value ?

Thanks
0
Comment
Question by:marper
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 100 total points
ID: 24818728
Select CASE
when myfield in ('val1' , 'val2' , 'val3') THEN 'A'
when myfield in ('val4' , 'val5') THEN 'B'
else 'C' end
0
 
LVL 75

Assisted Solution

by:Aneesh Retnakaran
Aneesh Retnakaran earned 100 total points
ID: 24818732
Select CASE
when myfield IN  ('val1' , 'val2' , 'val3') THEN 'A'
when myfield IN  ('val4' , 'val5') THEN 'B'
else 'C' END
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how the fundamental information of how to create a table.

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question