2012-06-15 106 views
0

我想做一个OLE DB命令来添加行到我的表只有当主键字段不存在于同一个表内。这是我到目前为止:Sql Server SSIS条件插入

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); 

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

谢谢!

+0

是否有原因在目标之前不使用查找转换来清除现有行? – billinkc

回答

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