Note that there are some explanatory texts on larger screens.

plurals
  1. POPrevent trigger from firing
    primarykey
    data
    text
    <p>I have the following trigger</p> <p>First trigger:</p> <pre><code>ALTER TRIGGER [dbo].[DIENSTLEISTUNG_Update] ON [dbo].[DIENSTLEISTUNG] INSTEAD OF UPDATE AS BEGIN SET NOCOUNT ON; DECLARE @intNewID int INSERT INTO [DIENSTLEISTUNG] (DESCRIPTION, QUANTITY, PRICE, AZ_MO, AZ_DI,AZ_MI,AZ_DO,AZ_FR, AZ_SA,AZ_SO,DIENSTLEISTUNGSART_ID, UPDATE_USER, UPDATE_DATE, PERMISSIONS, KONTRAKTPOSITION,ITEMNUMBER, PRIORITY, VALID) SELECT i.DESCRIPTION, i.QUANTITY, i.PRICE, i.AZ_MO, i.AZ_DI,i.AZ_MI,i.AZ_DO,i.AZ_FR, i.AZ_SA,i.AZ_SO,i.SERVICETYPE_ID, i.UPDATE_USER,GETDATE(), i.PERMISSIONS, i.KONTRAKTPOSITION,i.ITEMNUMBER, i.PRIORITY, 'Y' FROM INSERTED i JOIN deleted d ON i.ID=d.ID WHERE i.PRICE&lt;&gt;d.PRICE or i.DESCRIPTION&lt;&gt;d.DESCRIPTION IF ( UPDATE (PRICE) OR UPDATE (DESCRIPTION) ) UPDATE S SET s.VALID = 'N' FROM SERVICE s JOIN INSERTED i ON I.ID = S.ID IF UPDATE(PRIORITY) UPDATE s SET s.PRIORITY= i.PRIORITY FROM SERVICE s JOIN INSERTED i ON i.ID = s.ID SET NOCOUNT OFF; END </code></pre> <p>The first Trigger copies an entire row with a new ID if a change in the original row happens, also the trigger set a flag. The old row gets the flag <code>VALID = 'N'</code> and the new row gets the flag <code>VALID = 'Y'</code>. The trigger only creates a new row if <code>PRICE</code> or <code>DESCRIPTION</code> are updated. So far so good. </p> <p>My problem is that if I want to update the <code>PRIORITY</code> in the new row the trigger fires again and sets the flag to <code>VALID = 'N'</code>. That should not happen. I want only to update the priority without creating a new row or update a another column.</p> <p>Thanks for help</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload