How to get result from deleted row

  • Hi Guys

    I have a store proc that delete a row from a and I would like to get the result of the deleted row whether be =1 or True in order to execute another store proc. Could this be possible?

    ---- I am aware this code won't work I am trying to explain what I would like to accomplish
    DECLARE @RowToDelete int,@Result int
    SET @RowToDelete=1

    SELECT @Result=(DELETE from table where Id=@RowToDelete)

    IF @Result=1 --- Or whatever rusults is
       BEGIN
           EXEC('storeproc @param1, @param2)
       END

    Only if the deleted row is true then execute the store proc.

    TIA

    AL

    • This topic was modified 2 months, 3 weeks ago by mashispano.
  • CREATE TRIGGER TriggerName
    ON YourTableName
    AFTER DELETE
    AS
    BEGIN
    -- -- Check if any row was deleted (= 1 or True)
    IF EXISTS (SELECT 1 FROM DELETED)
    BEGIN
    -- Execute your stored procedure
    EXEC YourStoredProcedureName;
    END;
    END;
  • Try something like this ...

    DECLARE @RowToDelete int,@Result int;
    SET @RowToDelete=1;

    DELETE from table where Id=@RowToDelete;

    SELECT @Result = @@ROWCOUNT;

    IF @Result=1 --- Or whatever rusults is
    BEGIN
    EXEC storeproc @param1, @param2;
    END
  • I would lean towards DesNorton's solution as I dislike triggers and I think they get hidden/lost from future devs/DBAs.

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply