#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    2
    Rep Power
    0

    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
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jan 2003
    Location
    Paris Uppland
    Posts
    2,378
    Rep Power
    391
    Code:
    create trigger [dbo].[KkSalesLines] on dbo.[Sales Line] after delete as 
    begin
        insert into DeletedSalesLine
        select [Document No_],
               [Line No_]
          from deleted;
    end
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    2
    Rep Power
    0
    Thank you very much. Can't believe it was so simple.

IMN logo majestic logo threadwatch logo seochat tools logo