October 31st, 2012, 12:25 AM
-
Trigger with multiple lines
Good day. What am I trying to achieve is when line in Sales Line table in Navision is deleted then insert data from deleted record to new table.
This is working fine (with the code below) if I delete one single line, however not working for multiple lines. Can you help me to do same functionality for multiple lines.
Code:
USE [TEST]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER TRIGGER [dbo].[KkSalesLines]
ON [dbo].[Sales Line]
AFTER DELETE
AS
BEGIN
DECLARE @document_no nchar(20)
DECLARE @line_no nchar(20)
SET @document_no = (SELECT [Document No_] FROM deleted)
SET @line_no = (SELECT [Line No_] FROM deleted)
INSERT INTO DeletedSalesLine
VALUES(@document_no, @line_no);
END
October 31st, 2012, 03:45 AM
-
Code:
create trigger [dbo].[KkSalesLines] on dbo.[Sales Line] after delete as
begin
insert into DeletedSalesLine
select [Document No_],
[Line No_]
from deleted;
end
October 31st, 2012, 06:09 PM
-
Thank you very much. Can't believe it was so simple.