0

How can I use CASE statement in my WHERE condition along with IN clause? I am trying following query and its giving syntax error.

SELECT * FROM tblCustomers
WHERE custCode = 'CST1'
AND   CASE @accountType WHEN 'Doemstic'
      THEN city IN ('hokkaido','tokyo')
      ELSE city IN ('mumbai')
      END

This statement gives syntax error near 'IN'

I am using SQL Server 2012

Anil Soman
  • 2,443
  • 7
  • 40
  • 64

1 Answers1

1

when i have to do something similar, i try to write it in another way:

SELECT * FROM tblCustomers
WHERE 
custCode = 'CST1'
AND 
(
    (
        @accountType = 'Doemstic'
        AND 
        city IN ('hokkaido','tokyo')
    )
    OR
    (
        @accountType <> 'Doemstic'
        AND 
        city IN ('mumbai')
    )
)

if someone has a better idea, please share

AcidJunkie
  • 1,878
  • 18
  • 21