case statement assistance requested

  • 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,

  • You have your case set wrong

    It should be

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

    SELECT g.groupID, cfdn.CustomFieldID,

    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 AS [operand]

  • Ahh... thank you very much.

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

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