Help requested on using CASE

  • This piece of script says incorrect syntax near '=' and I am stumped at why. Thank you in advance for your assistance.

    exlcude is a column in the Criteria table.

    INSERT INTO Criteria (GroupID, CustomFieldID, RelationalOperator, Value)

    SELECT g.groupID, cfdn.CustomFieldID,

    CASE operand

    WHEN operand = 'equals' and exclude = 0 THEN '='

    WHEN operand = 'equals' and exclude = 1 THEN '<>'

    WHEN operand = 'like' and exclude = 0 THEN 'Like'

    WHEN operand = 'like' and exclude = 1 THEN 'not like'

    ELSE operand

    END

  • Sorry for posting in the wrong place. I have since found the T-SQL forum and will post this question there. Thank you.

  • Try this...

    SELECT g.groupID, cfdn.CustomFieldID,

    operand = CASE

    WHEN operand = 'equals' and exclude = 0 THEN '='

    WHEN operand = 'equals' and exclude = 1 THEN '<>'

    WHEN operand = 'like' and exclude = 0 THEN 'Like'

    WHEN operand = 'like' and exclude = 1 THEN 'not like'

    ELSE operand

    END

    DAB

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply