Solved

CASE syntax

Posted on 2009-07-09
2
173 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
2 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 25 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 25 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

815 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now