繁体   English   中英

使用列中的条件更新记录

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM