sqlserver 我有6个参数 如果这些参数有不为空的就不更新 不然会把原来的数据变成空 用if的话好像条件太复杂了 要怎么搞
update table1 set a=@a,b=@b,c=@c,d=@d,e=@e,f=@f where ...
update table1 set a=@a,b=@b,c=@c,d=@d,e=@e,f=@f where 当哪条不为空你就筛选出来了,比如a,b不为空:update table1 set c=@c,d=@d,e=@e,f=@f where a IS NOT NULL and b IS NOT NULL
上面那个不知道咋回事,发个图吧
这个问题提的有些含糊,比如开发平台,语言,框架的背景都没说明。
如果使用了具体的ORM,则不需要逐一判定,会自动组织为更新变化的sql语句;如果sql完全由程序拼写,就需要识别数据
控件的变更集合,动态拼写,这是一个公用方法,里面的基本构成是一个循环+一个判空分支
update table1 set
a=@a
b=@b
where id=
没见过你这个语句,不知道@是什么作用,但是我想都差不多吧
update table1 set a=@a,b=@b,c=@c,d=@d,e=@e,f=@f where (a is not null and b is not null and c is not null and d is not null and e is not null and f is not null )
当哪条不为空的时候就不更新,意思就是只有当数据库里所有字段原有的值都不是空值的时候,才更新数据。