Mutual exchange in SQL?

0 like 0 dislike
29 views
Given a table of transactions provodka
It is known that this table has transactions only with code 20501 and 20502.
How to replace all lines on 20501 20502, 20501 20502 on.

How to replace, for example 20501 20502 on, I understand. REPLACE( Code, 20501, 20502). Progressively replace does not work, because after the first replace in all rows is the value of 20502.
by | 29 views

3 Answers

0 like 0 dislike
Well, if only 2 values:
UPDATE provodka SET code = 41003 - code; # 20501 + 20502 == 41003

M - Mosk )
by
0 like 0 dislike
First to replace the third-any.
Second to replace the first.
The third replaced by the second.

L - logic

If you're bored you in other ways.
\rhttps://tproger.ru/problems/popular-ways-to-swap/
by
0 like 0 dislike
Why not use the solution vlob?
Pass at the table only happens once.
UPDATE provodka p SET p.code = CASE when p.code = 20501 20502 then when p.code = 20501 20502 then else p.code END
by

Related questions

0 like 0 dislike
1 answer
asked Apr 9, 2019 by Deefs
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
0 like 0 dislike
7 answers
110,608 questions
257,186 answers
0 comments
33,708 users