sql 更新语句 若某字段为空则更新此字段否则不更新

图片说明

update tablename set name=(case when name is null then '李先生' else name end),set sex=(case when sex is null then '男' else sex) where id=1

试试能解决你的问题吗?
update t_data set field1=(case when type='A' then 'X' else filed1 end)
,filed2=(case when type='B' then 'X' else filed2 end)

你可以把不更新字段名不写在更新语句里面,你就直接写你要更新得字段名就可以了。按理如果你设置为null应该也会被更新为null