Multiple case statements

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • weefrenchie
    New Member
    • Apr 2010
    • 9

    Multiple case statements

    Hi,
    I have a SQL query that looks like this:

    , CASE WHEN object 1 LIKE '%first%'
    OR object 1 LIKE '%second%'
    OR object 2 LIKE '%first%'
    OR object 2 LIKE '%second%'
    THEN object 3
    END AS [column 1]
    , CASE WHEN object 1 LIKE '%first%'
    OR object 1 LIKE '%second%'
    OR object 2 LIKE '%first%'
    OR object 2 LIKE '%second%'
    THEN object 4
    END AS [column 2]


    The whole query is quite long and so it runs quite slowly - I think it's because it goes through the whole of the database for each of the CASE statements? (there's 12 of them)

    Is there a way of embedding the CASE statements or something?

    What I'm trying to do is:

    IF object 1 LIKE (list of options1) OR object 2 LIKE (list of options2)
    THEN object 3 AS Column 1
    AND object 4 AS Column 2
    ...


    any ideas?

    Thanks!
  • ck9663
    Recognized Expert Specialist
    • Jun 2007
    • 2878

    #2
    Check your expressions and values if you can use the IN Operator.

    Happy Coding!!!

    ~~ CK

    Comment

    Working...