Click here to Skip to main content
15,889,462 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello,

i have to update my table:

id name city
1 test1 ahmedabad
2 test2 pune
3 test3 ahmedabad
4 test4 pune

update city ahmedabad to pune and pune to ahmedabad. like below:

id name city
1 test1 pune
2 test2 ahmedabad
3 test3 pune
4 test4 ahmedabad

thanks in advance.
Posted
Updated 27-May-13 21:42pm
v2

SQL
update tblnm set city = case when city = 'ahmedabad' then 'pune' else 'ahmedabad' end
where city in ('ahmedabad','pune')

Happy Coding!
:)
 
Share this answer
 
v2
Comments
kk2014 28-May-13 4:02am    
Hi aarti,

it works for me. i got exactly which i want.

thank.
Aarti Meswania 28-May-13 4:37am    
Welcome!
Glad to help you! :)
SQL
1) update Mytable set city='Ahmedabad' where id in (2,4)
2) update Mytable set city='Pune' where id in (3,1)'
 
Share this answer
 
Comments
kk2014 28-May-13 4:00am    
hi Basmed Awad,

thanks for the reply but i want to do that inine query. so solution 1 is working for me.

but thanks for the reply.

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