- This topic is empty.
Viewing 4 posts - 1 through 4 (of 4 total)
Viewing 4 posts - 1 through 4 (of 4 total)
- The forum ‘Other’ is closed to new topics and replies.
The forums ran from 2008-2020 and are now closed and viewable here as an archive.
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…
> I stumbled upon an SQL error in my code
Care to tell us what that error *was*?
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)
> 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!