Grow your CSS skills. Land your dream job.

SQL Error – Help!

  • # June 2, 2013 at 9:18 am

    Hello!

    I stumbled upon an SQL error in my code:

    UPDATE orders
    SET status_comanda = CASE ID
    WHEN 9 THEN ‘bun’
    WHEN 8 THEN ‘nebun’
    END,
    SET nr_awb = CASE ID
    WHEN 8 THEN ‘nebunicel’
    END,
    SET telefon = CASE ID
    WHEN 7 THEN ‘666DA’
    END,
    SET genre = CASE ID
    WHEN 6 THEN ‘M’
    END
    WHERE ID IN (9,8,7,6)

    What did I miss?

    PS: Only one SET statement works, though…

    __
    # June 2, 2013 at 2:26 pm

    > I stumbled upon an SQL error in my code

    Care to tell us what that error *was*?

    # June 3, 2013 at 2:18 pm

    Well, it didn’t tell me. It just said that I have an error. Anyway, the problem was that “SET” shouldn’t be used only at the start of the statement.
    Like this:

    UPDATE orders
    SET status_comanda = CASE ID
    WHEN 9 THEN ‘bun’
    WHEN 8 THEN ‘nebun’
    END,
    nr_awb = CASE ID
    WHEN 8 THEN ‘nebunicel’
    END,
    telefon = CASE ID
    WHEN 7 THEN ‘666DA’
    END,
    genre = CASE ID
    WHEN 6 THEN ‘M’
    END
    WHERE ID IN (9,8,7,6)

    __
    # June 3, 2013 at 3:26 pm

    > Well, it didn’t tell me. It just said that I have an error.

    It’s always helpful to share the *actual* error message, even if it seems vague.

    Are you running this directly in SQL, or from a program (e.g., PHP)? SQL error messages are usually quite useful, but you won’t necessarily see them if you’re running the query from another program – you need to ask for them specifically.

    Anyway, glad you solved it!

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".