我有一张桌子:
Employee (employeeID)
EmployeeRank (rankID, employeeID)
现在,我有另一个表,其中包含所有将要加薪的员工。
DueForRaise (rankID, employeeID)
我必须将DUeForRaise中的所有雇员插入到EmployeeRank表中,前提是他们不在同一级别。
我正在为特定的rankID @rankID进行此更新。
这行得通吗?
INSERT EmployeeRank ( rankID, employeeID)
SELECT rankID, employeeID
FROM DueForRaise dfr
OUTER JOIN EmployeeRank er er.employeeid = dfr.employeeid)
WHERE dfr.rankID = @rankID
最佳答案
怎么样:
insert into EmployeeRank
select * from DueForRaise p
where NOT EXISTS(
SELECT * FROM EmployeeRank WHERE rankID=p.rankID and employeeID=p.employeeID
);