Reputation: 11
I have this update query.
UPDATE production_shr_01
SET total_hours = hours, total_weight = weight, percentage = total_hours / 7893.3
WHERE (status = 'X')
The query executes fine but the problem is that when this query executes, it doesn't update the percentage field. What might be the problem?
Upvotes: 0
Views: 136
Reputation: 5145
In percentage = total_hours / 7893.3
clause, the old value of total_hours
will be used. Percentage
was updated but with the old value. So it looks like it was not updated. Please use percentage = hours/ 7893.3
Upvotes: 1
Reputation: 3183
Either status = 'X' doesn't find any rows or (and the next is more likely) since you update total_hours in the same statement, total_hours could be 0 (or NULL) and therefor no update; I'd suggest you use the hours field for updating like this:
UPDATE production_shr_01
SET total_hours = hours, total_weight = weight, percentage = hours / 7893.3
WHERE (status = 'X')
Upvotes: 5