How to compare a variable against multiple values in MSSQL

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Anil Verma
    New Member
    • Sep 2010
    • 1

    How to compare a variable against multiple values in MSSQL

    How to compare a SQL variable against multiple values:

    Here is the scenario;

    Code:
    Declare @JobTitle varchar(10)
    
    Select @JobTitle = JobTitle from tableName where xxx=xxx
    Now I want to compare @JobTitle value against multiple strings without using OR in the IF statement?

    Code:
    if @JobTitle = 'AAAAA' OR @JobTitle = 'BBBBBB' OR @JobTitle = 'CCCCC' ......
    instead of using multiple OR, is there any other way to accomplish this?
    Last edited by NeoPa; Sep 20 '10, 01:01 PM. Reason: Please use the [CODE] tags provided
  • gpl
    New Member
    • Jul 2007
    • 152

    #2
    Use IN, for example
    Code:
    @JobTitle IN ('AAAAA', 'BBBBBB', 'CCCCC')

    Comment

    Working...