【问题标题】:ignoring records with null values in them on insert在插入时忽略其中包含空值的记录
【发布时间】:2012-07-20 00:27:23
【问题描述】:

我有下表:

inventor(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 字段为空,则它不会插入到发明人表中

【问题讨论】:

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


    【解决方案1】:

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

    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;
    

    【讨论】:

    • 天哪,这让我笑了...这么简单的问题,我拼命想把它复杂化...谢谢@Daniel Cook!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-12-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-21
    • 2015-07-31
    相关资源
    最近更新 更多