Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $id_active = 1;
- $id_swap = 2;
- UPDATE article_test
- // the column to update is 'sort_id' and since it is also the column I need to test, then I use the same value for CASE right?
- SET sort_id = CASE sort_id
- WHEN $id_active THEN $id_swap // sort_id 1 to become sort_id 2
- WHEN $id_swap THEN $id_active // sort_id 2 to become sort_id 1
- WHERE sort_id IN ($id_swap,$id_active) // test only rows with sort_id 1 & sort_id 2
- UPDATE article_test
- SET sort_id =
- CASE
- WHEN sort_id = $id_active THEN $id_swap
- WHEN sort_id = $id_swap THEN $id_active
- ELSE sort_id
- END
- WHERE sort_id IN ($id_swap, $id_active)
- CASE sort_id
- WHEN $id_active THEN $id_swap
- WHEN $id_swap THEN $id_active
- ELSE sort_id
- END
- CASE
- WHEN sort_id = $id_active THEN $id_swap
- WHEN sort_id = $id_swap THEN $id_active
- WHEN sort_id LIKE '' THEN blah
- ELSE sort_id
- END
- UPDATE article_test
- SET sort_id = CASE sort_id
- WHEN $id_active THEN $id_swap
- WHEN $id_swap THEN $id_active
- else sort_id end
- ....
Add Comment
Please, Sign In to add comment