Solved

CASE syntax

Posted on 2009-07-09
2
170 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

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 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…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

743 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

10 Experts available now in Live!

Get 1:1 Help Now