I have some views I'm working with, and I need to set up a trigger to prevent the deletion of any data within the view if the data table is locked by a variable in another table. I already have the trigger set up, and have no issue with setting up the replacement of the delete command using an 'INSTEAD OF DELETE' trigger, but my issue now is how to preserve the incoming delete query for the times where deletions *are* allowed. In this case, I'm using SQL Server.

For example, if the control table says my view is locked, then any delete query sent to the database should be stopped, and an error message should be returned (no problems here, have this already). However, if the control table says my view is unlocked, I need to be able to allow the delete query to delete data from the view (here I need help).

Code:

```
CREATE TRIGGER [database_name].[trigger_name]
ON [database_name].[view_name]
INSTEAD OF DELETE
AS
BEGIN
    SET NOCOUNT ON

    IF NOT EXISTS (SELECT * FROM [database_name].[control_table_name]
                   WHERE Control_Item = 'view_name' AND Can_modify = 'N')
    BEGIN
        SET NOCOUNT OFF
        --NEW DELETION STATEMENT GOES HERE, NEEDS TO BE DUPLICATE OF REPLACED DELETE QUERY--
    END
    ELSE
    BEGIN
        RAISEERROR('Deletions are currently disabled!', 11, 1);
    END
END

```

I'm sure there's some stupid logic statement or something I'm missing but I'll appreciate all the help I can get. Thanks!