我有两个表:PS_Emp和PS_SAR_General
存储过程应使用PS_Emp中该表中不存在的任何员工ID更新PS_SAR_General。你能告诉我我哪里出问题了吗?
这是我到目前为止所拥有的:
CREATE PROCEDURE [dbo].[SAR_NewEmp_app]
@USID
AS
INSERT INTO dbo.PS_SAR_General ([USID])
VALUES (@USID)
FROM dbo.PS_Emp
WHERE NOT EXISTS (SELECT PS_Emp.[USID] FROM PS_Emp WHERE PS_SAR_General
[USID] = PS_Emp.[USID]) AND PS_Emp.[Status] = 'Active' AND
PS_Emp.[ECS ICS] = 'ECS' AND PS_Emp.[Employee Class] NOT IN
('BRWDRESORCE', 'SUBCONTRACT')
答案 0 :(得分:0)
对于其他在这里寻找答案的人来说,最终的结果是:
CREATE PROCEDURE [dbo].[SAR_AddNewEmps_app]
AS
INSERT INTO dbo.PS_SAR_General ([USID], [Status], [ECS ICS], [Employee Class])
SELECT PS_SAR_General.USID, PS_SAR_General.[Status]
, PS_SAR_General.[ECS ICS], PS_SAR_General.[Employee Class]
FROM dbo.PS_SAR_General
WHERE NOT EXISTS (
SELECT PS_Emp.[USID]
FROM PS_Emp
WHERE PS_SAR_General.[USID] = PS_Emp.[USID]
) AND [Status] = 'Active'
AND [ECS ICS] = 'ECS'
AND [Employee Class] NOT IN ('BRWDRESORCE', 'SUBCONTRACT')
此存储过程现在添加了新表中不存在但在employee表中存在的行。