MSSQL多个更新行 [英] MSSQL multiple update row
本文介绍了MSSQL多个更新行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,
如何运行此sql代码?
Hello,
How can i run this sql code?
Update Urun set id=2 where id=1;
Update Urun set name='Ron' where id=3;
当我尝试运行此代码时出现错误
我尝试了什么:
分开运行此代码并且它正常工作
When i try to run this code i got error
What I have tried:
run this code separatly and it work correctly
推荐答案
您可以使用案例陈述
You can use case statement
Update Urun Set id=(case when id=1 Then 2 else id end),name =(case when id=3 then 'Ron' else name end)
Where id in(1,3)
更新Urun
设置id =(当id = 1时的情况2其他id结束),
name =(当id = 3然后'Ron'其他名称结束时的情况)
其中id在(1,3)
Update Urun
Set id=(case when id=1 Then 2 else id end),
name =(case when id=3 then 'Ron' else name end)
Where id in(1,3)
这篇关于MSSQL多个更新行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文