This article is half-done without your Comment! *** Please share your thoughts via Comment ***
Check the below input data and expected output to swap the values in the table.
Input Data:
1 2 3 4 5 6 7 8 |
Col ---- M N N M N N |
Expected Output:
1 2 3 4 5 6 7 8 |
Col ---- N M M N M M |
Create a table with data:
1 2 3 4 5 6 7 |
CREATE TABLE SwapColumnData (Col CHAR(1)) GO INSERT INTO SwapColumnData VALUES ('M'),('N'),('N'),('M'),('N'),('N') GO |
Solution:
1 2 3 4 5 |
UPDATE t SET t.Col = s.Col FROM SwapColumnData t INNER JOIN SwapColumnData s ON t.Col <> s.Col |
Please try the different solution for this puzzle and share it via comment...