[英]Update records with conditions on columns
我想用匹配的id
更新table1
的记录name,appid
。 下面的语句将使用下面的语句更新table1的值
update table1 set name=@name,appid=@appid where id=@id
我还要一个条件。 更新此id
所有记录,但如果(@appid is null or id=54)
,则appid
不应更新。 我如何对一列( appid
)进行限制(条件)。 还是我必须写另一个更新声明? 我可以格式化以上查询。 请帮忙
update table1 set
name = @name,
appid = (case when @appid is null or id=54 then appid else @appid end)
where id=@id
这对您有帮助吗?
update
table1
set name=@name,
appid=ISNUL(@appid, appid)
where
id=(CASE WHEN @id=54 THEN id+1 ELSE @id END)
update table1 set name=@name,
appid= Case when id=54 then appid else Coalesce(@appid,appid) end where id=@id
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.