我正在尝试执行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);
基本上我只想要一个条件插入语句。
谢谢!
答案 0 :(得分: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