什么方法能显示下面的要求?
数据库有2张表 tb1 tb2,
从TB2里面更新TB1里面的内容,如果TB2里面某个字段的值为空 ,TB1里面改字段的值保持不变(如下图
tb2里面的c ,d 跟新 a,b 字段, 如果d 里面有的值为空,那么b的值不变)
tb1 tb2 tb1
id a b id c d id a b
1001 20 30 1001 15 null 1001 15 30
数据库有2张表 tb1 tb2,
从TB2里面更新TB1里面的内容,如果TB2里面某个字段的值为空 ,TB1里面改字段的值保持不变(如下图
tb2里面的c ,d 跟新 a,b 字段, 如果d 里面有的值为空,那么b的值不变)
tb1 tb2 tb1
id a b id c d id a b
1001 20 30 1001 15 null 1001 15 30
set a = ISNULL(tb2.c, tb1.a),
b = ISNULL(tb2.d, tb1.b)
from tb2
where tb1.id = tb2.id
set a = case when tb2.a <> '' then tb2.a else tb1.a,
b = case when tb2.b <> '' then tb2.b else tb1.b
from tb2
where where tb1.id = tb2.id
set tb1.a= case when tb2.a is not null then tb2.a else tb1.a end,
tb1.b= case when tb2.b is not null then tb2.b else tb1.b end
from tb2 where tb1.id = tb2.id