Click here to Skip to main content
15,868,016 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How can i interchange two rows in sql server

eg:

ID name priority age
1 robin 1 23
2 anish 2 24


i need to interchange the priority as

ID name priority age
1 robin 2 23
2 anish 1 24

Thanks in adavance
Posted
Comments
CHill60 21-Oct-14 11:37am    
So you want to change anything that is priority 2 to priority 1?
Kochathu Thomas Tinu 21-Oct-14 11:40am    
thanks for the response. Yes i need to change only the priority without changing any values in the table

1 solution

Try this:
SQL
UPDATE Table_1
SET priority =
    CASE id
    WHEN 1 THEN (SELECT priority FROM Table_1 WHERE id = 2)
    WHEN 2 THEN (SELECT priority FROM Table_1 WHERE id = 1)
    END
WHERE id IN (1, 2)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900