SQL Case Update Statement Error Message

  • I keep getting an incorrect syntax error on this CASE statement.

    (Msg 156, Level 15, State 1, Line 5

    Incorrect syntax near the keyword 'like'.

    Can you not use the % character in a CASE statement or is the overall syntax wrong? Thank you.

    Update Billed

    set bill_amount =

    Case When product_Code like '%0000' then STATE_DUES

    When product_code like 'CHAPT/%' and not like '%0000' Then Local_dues

    Else '9999'

    End

    where billed.ID = '123456'

  • Hi Roger:

    Update Billed

    set bill_amount =

    Case When product_Code like '%0000' then STATE_DUES

    When product_code like 'CHAPT/%' and product_code not like '%0000' Then Local_dues

    Else '9999'

    End

    where billed.ID = '123456'

    Cheers

    ChrisM

    “Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

    For fast, accurate and documented assistance in answering your questions, please read this article.
    Understanding and using APPLY, (I) and (II) Paul White
    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden

  • Thanks! I should have tried that!

    Roger

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

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