【问题标题】:Sql Server SSIS conditional insertionSql Server SSIS 条件插入
【发布时间】:2012-06-15 13:12:44
【问题描述】:

我正在尝试执行 OLE DB 命令,仅当同一表中不存在主键字段时才向我的表中添加行。这是我目前所拥有的:

insert into employee
   (employee_id, first_name, middle_initial, last_name)   /*fields of the employee table*/
   values (employeedID, firstName, mInitial, lastName)    /*columns from my input       */

 /* only insert into the table where employee_ID is not already in the table */
 where ((select employee_id from employee where employee_id = employeeID) = NULL);  

基本上我想要的只是一个条件插入语句。

谢谢!

【问题讨论】:

  • 您是否有理由不在目的地之前使用查找转换来清除现有行?

标签: sql-server insert ssis conditional bids


【解决方案1】:

我不确定您的包是如何设置的,但您可以考虑使用没有任何限制的临时表。首先将所有记录插入其中,然后在末尾声明如下:

insert into employee (employee_id, first_name, middle_initial, last_name) 
select t.employee_id, t.first_name, t.middle_initial, t.last_name
from temp_employee AS t
left join employee ON t.employee_id = employee.employee_id
where employee.employee_id is null

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-02
    • 1970-01-01
    相关资源
    最近更新 更多