0

主キー フィールドが同じテーブル内にまだ存在しない場合にのみ、テーブルに行を追加する 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);  

基本的に私が欲しいのは条件付き挿入ステートメントだけです。

ありがとう!

4

1 に答える 1

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
于 2012-06-15T13:20:09.917 に答える