I am trying to Insert data in a table named "Candidate_Post_Info_Table_ChangeLogs"
whenever a record is updated in another table named "Candidate_Personal_Info_Table"
. my code works fine whenever a single record is updated but when i try to updated multiple rows it gives error:
"Sub query returned more then 1 value".
Following is my code :
ALTER TRIGGER [dbo].[Candidate_PostInfo_UPDATE]
ON [dbo].[Candidate_Post_Info_Table]
AFTER UPDATE
AS
BEGIN
IF @@ROWCOUNT = 0
RETURN
DECLARE @Candidate_Post_ID int
DECLARE @Candidate_ID varchar(50)
DECLARE @Action VARCHAR(50)
DECLARE @OldValue VARCHAR(MAX)
DECLARE @NewValue VARCHAR(MAX)
DECLARE @Admin_id int
IF UPDATE(Verified)
BEGIN
SET @Action = 'Changed Verification Status'
SET @Candidate_Post_ID = (Select ID From inserted)
SET @Candidate_ID = (Select Identity_Number from inserted)
SET @NewValue = (Select Verified From inserted)
SET @OldValue = (Select Verified From deleted)
IF(@NewValue != @OldValue)
BEGIN
INSERT INTO Candidate_Post_Info_Table_ChangeLogs(Candidate_Post_ID, Candidate_ID, Change_DateTime, action, NewValue, OldValue, Admin_ID)
VALUES(@Candidate_Post_ID, @Candidate_ID, GETDATE(), @Action, @NewValue, @OldValue, '1')
END
END
END
i have searched stack overflow for this issue but couldn't get any related answer specific to this scenario.