update a set a.weight = b.weight from a,b where a.wlid = b.wlid
update a set a.weight = b.weight from a,b where a.wlid = b.wlid
报错了..... Cannot insert the value NULL into column 'weight', table 'MRP2.dbo.dWLID'; column does not allow nulls. UPDATE fails. The statement has been terminated.
是不是我的表有问题,weight这列我是不允许为空的
update a set a.weight = b.weight from a,b where a.wlid = b.wlid
--将a中weight为null且不存在于b的设为0 update a set weight = 0 where not exists(select 1 from b where a.wlid = b.wlid) and a.weight is null--更新存在于b的 update a set a.weight = isnull(b.weight,0) from a,b where a.wlid = b.wlid
update a
set a.weight = b.weight
from a,b
where a.wlid = b.wlid
set a.weight = b.weight
from a,b
where a.wlid = b.wlid
Cannot insert the value NULL into column 'weight', table 'MRP2.dbo.dWLID'; column does not allow nulls. UPDATE fails.
The statement has been terminated.
set a.weight = b.weight
from a,b
where a.wlid = b.wlid
因为b表中的资料并不全等于a表的资料,就是说b的资料少于a的资料
而且a表中的weight这个字段是不允许为空的
可不可判断如果为空的就用 0 来代替
update a
set weight = 0
where not exists(select 1 from b where a.wlid = b.wlid)
and a.weight is null--更新存在于b的
update a
set a.weight = isnull(b.weight,0)
from a,b
where a.wlid = b.wlid
B表是EXCEL导入的,里面有null没注意