如何在sql server中更新多个值 [英] how to update multiple values in sql server

查看:87
本文介绍了如何在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.


这篇关于如何在sql server中更新多个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆