?
Solved

CASE syntax

Posted on 2009-07-09
2
Medium Priority
?
179 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

What Is Blockchain Technology?

Blockchain is a technology that underpins the success of Bitcoin and other digital currencies, but it has uses far beyond finance. Learn how blockchain works and why it is proving disruptive to other areas of IT.

Question has a verified solution.

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

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how the fundamental information of how to create a table.
Suggested Courses

764 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