PDA

View Full Version : shorthand for multiple updates of same field on different records?


Leeoniya
02-04-2008, 06:30 PM
i was wondering if there was an alternative to doing multiple updates to the same field for a number of records without a bunch of update statements.

i need to renumber/reorder a set of fields, assuming "position_num" is a DB field, and i need to update it for records with ids 1,2,3 with position numbers of 21,22,23 respectively, is there a way to do this in one statement?

thanks,
Leon

Fumigator
02-04-2008, 10:42 PM
In that very specific case you could do SET position = id + 20 WHERE id in (1, 2, 3) but to carry that over to some sort of programmatic process would probably not work very well.