Question : Write a trigger which, when the salary of any employee(s) is updated, inserts a single record into this audit table with the total amount of the change across all employees.

I had to revise my question since people think it's different.

Table TBL_EMP_AUDIT is defined as follows:

create table TBL_EMP_AUDIT
(auditid int primary key identity(1,1),
notes varchar(200),
delta money)

 I need to write a trigger which, when the salary of any employee(s) is updated, inserts a single record into this audit table with the total amount of the change across all employees.

e.g. if five employees were given $1000 pay cut in a single update statement, the audit table should contain one row with values delta = -5000, notes = ‘Salaries updated’

I found a similar question about it on EE but they had set amounts that the salary will be reduced or added. It has to be variable.

Thanks for all your help in advance

Answer : Write a trigger which, when the salary of any employee(s) is updated, inserts a single record into this audit table with the total amount of the change across all employees.

Depends on your definition of delta.
Normally is is current - previous, so inserted - deleted.
It looks ok otherwise.

You may want to remove @affected_rows, since it is redundant.
Random Solutions  
 
programming4us programming4us