I need syntax help. Bit of a newbie trying to teach themselves IF/LIKE/OR

Liv_Stearns
Liv_Stearns Member
edited February 6 in Beast Mode

The specific task is to identify if a truck is a F-250,350, 2500, or 3500. The Column is "model" that I'm looking for the partial match in the model column. I keep getting syntax errors.

CASE

WHEN 
`model`LIKE ‘%F 250%’
OR `model` LIKE ‘%F-250%’
OR `model` LIKE ‘%F250%’
OR `model` LIKE ‘%E-350%’
OR `model` LIKE ‘%E-250%’
OR `model` LIKE ‘%2500%’
OR `model` LIKE ‘%3500%’
THEN 110
When `Actual bid 2` > 2500 THEN 120
ELSE 110

END

Just kidding never mind I fixed it.

I needed to use IN instead of LIKE
CASE

   WHEN `model`IN ('%F 250%')
OR 'model' IN ('%F-250%')
OR 'model' IN ('%F250%')
OR 'model' IN ('%F-350%')
OR 'model' IN ('%F350%')


THEN 110
When `Actual bid 2` > 2500 THEN 120
ELSE 110

END

Best Answer

  • DavidChurchman
    Answer ✓

    Good troubleshooting. Quick tip: since you're using IN, you could simplify it down to a list instead of a bunch of ORs:

    WHEN `model` IN ('%F 250%', '%F-250%', '%F250%', '%F-350%', '%F350%')
    THEN 110
    When `Actual bid 2` > 2500 THEN 120
    ELSE 110

Answers

  • And I figured it out I needed to be using IN instead of LIKE

  • DavidChurchman
    Answer ✓

    Good troubleshooting. Quick tip: since you're using IN, you could simplify it down to a list instead of a bunch of ORs:

    WHEN `model` IN ('%F 250%', '%F-250%', '%F250%', '%F-350%', '%F350%')
    THEN 110
    When `Actual bid 2` > 2500 THEN 120
    ELSE 110