tags:

views:

59

answers:

2

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?

+5  A: 

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')
riffnl
+1  A: 

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

Sujee