Results 1 to 4 of 4

Thread: Event Trigger

Threaded View

  1. #1

    Thread Starter
    Hyperactive Member Greyskull's Avatar
    Join Date
    Dec 2003
    Location
    somewhere in England
    Posts
    382

    Event Trigger

    Hello all,

    Here is the situation, I want to create a trigger so that whenever a field gets updated say salary is increased by £2000, i want it to record a history that there was a £2000 increase, be it one record update or multiple records.

    Here is what I currently have as my code:
    Code:
    ALTER TRIGGER [dbo].[Audit_Update] On [dbo].[tblEmployee]
    FOR UPDATE
    AS
    
    DECLARE @notes VARCHAR(200);
    DECLARE @DELTA MONEY;
    
    SELECT @DELTA = e.Salary From tblEmployee e
    SET @Notes='SALARIES UPDATED'
    
    IF UPDATE(Salary)
    	INSERT INTO TBL_EMP_AUDIT (notes, delta) VALUES (@Notes, @Delta)
    The above code records the value that was on the last record it processed i.e record had £15000 it will record £15000 instead of it saying
    '£5000'.


    Thanks in advance,
    Last edited by Greyskull; Jul 14th, 2009 at 09:37 AM.
    Please go to the Thread Tools menu and click Mark Thread Resolved when your post is answered
    If someone helped you today then please consider rating their post.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width