如何在sql server中更新多个值

问题描述:

I have dat like below

Col
1
2
2
2
2
1
1
1
1

Here if want update where ever the values 2 that should be changed as 1 and where the value is 1 that should be 2 for that how can i write the query with update



Update tablename set col =1 where col =2 
Update tablename set col =2 where col =1

I want to put both in single command.Could you please help me.

如果问题真的那么简单如上所述,然后使用case:



If the problem is truly as simple as stated, then use "case":

update tablename
set col = case col
          when 1 then 2
          else 1 end





这也照顾where子句。



我加倍你的问题非常简单,所以请确保你自己检查查询。



That also takes care of the where clause.

I double you problem is quite that simple so make sure that you check the query for yourself.