2012-06-15 135 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