Guest User

Untitled

a guest
Jan 16th, 2019
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. $id_active = 1;
  2. $id_swap = 2;
  3.  
  4. UPDATE article_test
  5. // 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?
  6. SET sort_id = CASE sort_id
  7. WHEN $id_active THEN $id_swap // sort_id 1 to become sort_id 2
  8. WHEN $id_swap THEN $id_active // sort_id 2 to become sort_id 1
  9. WHERE sort_id IN ($id_swap,$id_active) // test only rows with sort_id 1 & sort_id 2
  10.  
  11. UPDATE article_test
  12. SET sort_id =
  13. CASE
  14. WHEN sort_id = $id_active THEN $id_swap
  15. WHEN sort_id = $id_swap THEN $id_active
  16. ELSE sort_id
  17. END
  18. WHERE sort_id IN ($id_swap, $id_active)
  19.  
  20. CASE sort_id
  21. WHEN $id_active THEN $id_swap
  22. WHEN $id_swap THEN $id_active
  23. ELSE sort_id
  24. END
  25.  
  26. CASE
  27. WHEN sort_id = $id_active THEN $id_swap
  28. WHEN sort_id = $id_swap THEN $id_active
  29. WHEN sort_id LIKE '' THEN blah
  30. ELSE sort_id
  31. END
  32.  
  33. UPDATE article_test
  34. SET sort_id = CASE sort_id
  35. WHEN $id_active THEN $id_swap
  36. WHEN $id_swap THEN $id_active
  37. else sort_id end
  38. ....
Add Comment
Please, Sign In to add comment