在插入时忽略其中包含空值的记录

时间:2012-07-20 00:27:24

标签: sql sql-server sql-server-2008 insert

我有下表:

发明人( inventorID PatentNo ,InventorFirst,InventorLast,City,State)

其中inventorid是pk,patentno是fk。

这是当前的插入代码:

insert into Inventor (PatentNo, InventorFirst, InventorLast, City, statename, country, NationalityCountry, ResidenceCountry)
select PatentNo, InventorFirstname, InventorLastname, City, statename, country, NationalityCountry, ResidenceCountry
from InventorUpdate;

我想修改这个,以便如果InventorFirstname& InventorLastname字段为空,然后它不会插入发明人表

1 个答案:

答案 0 :(得分:4)

如何保留那些字段为空的记录被选中?

insert into Inventor (PatentNo, InventorFirst, InventorLast, City, statename, country, NationalityCountry, ResidenceCountry)
select PatentNo, InventorFirstname, InventorLastname, City, statename, country, NationalityCountry, ResidenceCountry
from InventorUpdate
Where InventorFirstname is not null 
And   InventorLastname is not null;