Hi @Analyst_SQL ,
You could also modify the update trigger like below:
CREATE TRIGGER [dbo].[TI_Tbl_Leaves_Update] ON [dbo].[tbl_Leaves]
AFTER Update
AS
BEGIN
DELETE M
FROM [dbo].Tbl_Leaves_Details M
INNER JOIN Inserted I
ON I.L_ID = M.L_ID;
;WITH CTE AS (
SELECT L_ID, L_From_Date, L_To_Date
FROM inserted
UNION ALL
SELECT L_ID, DATEADD(day, 1, L_From_Date) AS L_From_Date, L_To_Date
FROM CTE
WHERE L_From_Date < L_To_Date
)
INSERT INTO Tbl_Leaves_Details(L_ID,L_Date,L_Qty)
SELECT L_ID, L_From_Date, 1 AS L_Qty
FROM CTE;
END
Best regards,
Melissa
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.