user393964
user393964

Reputation:

Problem with where clause while updating database record

I have a screen in ABAP that makes it possible to update a database row. It's sort of working: I can update the 'row' but the problem is, that it's updating EVERY row in the table and not the one specified in the where clause.

This is the code I'm using:

UPDATE zmotoren_jat SET:
prijs = zmotoren_jat-prijs,
naam = zmotoren_jat-naam
WHERE motorid = zmotoren_jat-motorid. "this line doesn't seem to work!

Any idea why this won't work? I'm sure that 'motorid' exists: I'm not getting an error and I'm using the same line, motorid = zmotoren_jat-motorid to delete a row, which does work.

Upvotes: 2

Views: 2600

Answers (2)

mydoghasworms
mydoghasworms

Reputation: 18613

Your problem seems to have to do with the colon (:) in the first line, and the comma (,) in the second line.

The colon introduces chained statements, and it could be seeing the first one with prijs as a separate statement, thereby updating all records in the first statement (because the WHERE clause then only applies to the second statement).

Take out the colon and remove the comma between the SET specifiers and try again.

See Esti answer for an explanation with some example code.

Upvotes: 4

Esti
Esti

Reputation: 3687

Mydog has the correct answer.

Basically your syntax translates to the following:

UPDATE zmotoren_jat SET prijs = zmotoren_jat-prijs.
UPDATE zmotoren_jat SETnaam = zmotoren_jat-naam
 WHERE motorid = zmotoren_jat-motorid.

i.e it updates the price for every record in the table, and then updates the name for the specified ID. what you want is

UPDATE zmotoren_jat 
  SET prijs = zmotoren_jat-prijs
      naam  = zmotoren_jat-naam
WHERE motorid = zmotoren_jat-motorid.

Upvotes: 2

Related Questions