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
Solved

CASE syntax

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

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

840 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