Forum Moderators: coopster
I screwed up an application and now have corrupt data in a table. It's not a huge deal, but a manual fix at this stage would mean me going through about 1,200 records and hand editing ;-)
I think I can automate this, as all the data is there, it's just sometimes the wrong value appears in a field.
I have a table with the following fields:-
user
seconds
debit
In all of the corrupt records, debit is -1 (the result of me making an error in a function return -1 then forgetting to deal with the error, instead adding -1 to the debit field - DOH!).
So, eg, I might have the following record as one of the faulty ones:-
user seconds debit
trillianjedi 152 -1.00
The true value of what is currently -1 in the debit field is really easy to obtain - it's seconds * x (where x is a float value and constant).
Is there anyway I can build something to fix this automagically?
In rough logic language, it would be :-
Return all fields where debit = -1
Update each debit field to (seconds * x)
Loop to finish.
Can I do that in a single SQL statement, or would it be easier to build a php script to call from the command line to do it?
This is a one-off - the main app producing the defective data is now repaired.
Many thanks!
TJ