• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 647
  • Last Modified:

Syntax for CASE WHEN with multiple criteria

UPDATE #tmp
SET   Product_Type = CASE plcy.PTYP_ID WHEN 4 OR 8 OR 11 OR 15 OR 16 OR 17) then 'B' else 'A' END

What's the correct syntax for CASE WHEN {multiple values} THEN {something} END?

TIA
-Jim
0
Jim Horn
Asked:
Jim Horn
3 Solutions
 
flavoCommented:
CASE WHEN plcy.PTYP_ID  = 4 OR plcy.PTYP_ID  = 8 OR plcy.PTYP_ID  =  11 OR plcy.PTYP_ID  = 15 OR plcy.PTYP_ID  = 16 OR plcy.PTYP_ID  = 17)
0
 
morisceCommented:
UPDATE #tmp
SET  Product_Type = CASE when plcy.PTYP_ID in ( 4,  8, 11,15, 16,17) then 'B' else 'A' END
0
 
Jim P.Commented:
Have you tried:
----------------------------------------
UPDATE #tmp
SET   Product_Type = CASE plcy.PTYP_ID WHEN 4, 8, 11,  15, 16, 17 then 'B' else 'A' END
0
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!

 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorAuthor Commented:
Thanks guys.  I was using the IN, but for some reason not able to get it to work.
0
 
Jim P.Commented:
>>  16 OR 17) then 'B' els

You had an unclosed paren in the original.
0
 
Jim P.Commented:
Glad to be of assistance. May all your days get brighter and brighter.
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!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now