I have a SQL Server table for user skills with priority order for each user as this:
+----+------+----------+----------+
| ID | user | skill | priority |
+----+------+----------+----------+
| 1 | foo | swimming | 1 |
+----+------+----------+----------+
| 2 | foo | running | 2 |
+----+------+----------+----------+
| 3 | foo | hunting | 3 |
+----+------+----------+----------+
| 4 | boo | swimming | 1 |
+----+------+----------+----------+
| 5 | moo | swimming | 1 |
+----+------+----------+----------+
| 6 | moo | running | 2 |
+----+------+----------+----------+
How can I write SQL code to re-order the priority column values (an integer) for all skills for a user when the priority value is changed for one of the skills?
For example: for user "foo" I will change the priority of the skill "swimming" from (1) to (2); the update statement must also change the priority for all other skills for that user, in a dynamic way.
So in that example "swimming" will be priority (2) instead of (1), running will be (1) instead of (2), and the others will remain the same.