我有下面的触发器写入,它对单列更新(firstname)完全正常,但是我们现在需要更新一些额外的列(lastname,mobileNumber等)
CREATE TRIGGER apl.updateJaWithCandidateDataAfterInsert ON [APL].[tblJobApplications_v2]
AFTER INSERT
AS
SET NOCOUNT ON
UPDATE [APL].[tblJobApplications_v2]
SET FirstName = (
SELECT FirstName
FROM [USR].[tblUserDetails]
WHERE inserted.CandidateId = [USR].[tblUserDetails].CandidateId
)
FROM [APL].[tblJobApplications_v2]
INNER JOIN Inserted ON [APL].[tblJobApplications_v2].CandidateId = Inserted.CandidateId
GO
尝试了一些选择,但无法使这些工作。有人可以指出我正确的方向吗?
答案 0 :(得分:0)
[USR].[tblUserDetails]
UPDATE [APL].[tblJobApplications_v2]
SET FirstName = [USR].[tblUserDetails].FirstName,
LastName = [USR].[tblUserDetails].LastName
FROM [APL].[tblJobApplications_v2]
INNER JOIN Inserted ON [APL].[tblJobApplications_v2].CandidateId = Inserted.CandidateId
INNER JOIN [USR].[tblUserDetails] ON inserted.CandidateId = [USR].[tblUserDetails].CandidateId