Answers to Using value in deleted record in SQL Server ( 2 )

  1. 2017-01-01 10:01

    I think you can't run those with each other.

    I suggest you to use a (temporary table): tempIds(id int). Then use output clause like this:

    delete top(1) from temp
    output deleted.id into tempIds;
    

    Note: It's better to use CTE to delete first row.

    Then query over tempIds table and after that clear tempIds.

  2. 2017-01-01 10:01

    Try this way.. it may help you out.

    DECLARE @ID_CAPTURE TABLE (ID Int)
    DELETE TOP(1) FROM TEMP
    OUTPUT deleted.Nu into @ID_CAPTURE
    
    SELECT * FROM FLAT WHERE NU IN (SELECT * FROM @ID_CAPTURE)
    

    The above snippet will work for you in case of multiple records too.

Leave a reply to - Using value in deleted record in SQL Server

◀ Go back