I have a trigger that I am using to Audit a table in SQL 2000. It is an Update, Delete trigger and it works fine recording the deleted or updated rows. Here is the problem: the table I am auditing is for expenses that are approved by 2 other staff. This approval is already tracked. When an Expense is approved it triggers the Update (as the record is updated) but I do not want it written to the Audit table. What I am looking for is changes made to data but not the approval/review of the expense.
In other words if I changed an account code on my expense from what I originally submitted I would want to know that in the Audit but wouldn't want to know in the Audit that my boss approved the original expense.
There are lots of columns being monitored.
Here is the Trigger:
/****** Object: Trigger dbo.Update_for_Reject_Audi
t_tr Script Date: 9/5/2007 8:24:42 AM ******/
CREATE TRIGGER [Update_for_Reject_Audit_t
r]
ON pawsxexp FOR DELETE, UPDATE
AS
if Update (last_edit_date)
--!TR_VERSION:V1.00;;
BEGIN
-- Audit OLD record.
INSERT INTO cbf_audit_pawsxexp_deletes
(resource_code,period_end_
date,tran_
date,trx_d
etail_id ,
client_code,project_code, subproject_code, expense_code,
natural_cost_taxinc_rate,q
ty,reimbur
sement_cos
t_taxinc_a
mt,
mop_code,reimb_flag,nochar
ge_flag,re
ceipt_flag
,details,
posted_state,approved_stat
e,
data_source,approved_by_st
aff_code,
approved_date,batch_ctrl_n
um,manual_
entry_flag
,
clients_reference,project_
id,approve
d_rule,
created_date,created_user,
last_edit_
date,
reviewed_state,reviewed_by
_staff_cod
e,reviewed
_date,
reviewed_rule,natural_cost
_tax_amt,n
ocharge_co
de,
nocharge_notes,location_co
de,referen
ce_code,na
tural_cost
_amt,
natural_sell_amt,markup_pc
t,last_edi
t_user,tax
_code,post
_ctrl_num,
rejection_desc,rejection_a
dvised_fla
g,
activity_code,analysis_cod
e,activity
_type_code
, Change_User, change_date)
SELECT resource_code,period_end_d
ate,tran_d
ate,trx_de
tail_id ,
client_code,project_code, subproject_code, expense_code,
natural_cost_taxinc_rate,q
ty,reimbur
sement_cos
t_taxinc_a
mt,
mop_code,reimb_flag,nochar
ge_flag,re
ceipt_flag
,details,
posted_state,approved_stat
e,
data_source,approved_by_st
aff_code,
approved_date,batch_ctrl_n
um,manual_
entry_flag
,
clients_reference,project_
id,approve
d_rule,
created_date,created_user,
last_edit_
date,
reviewed_state,reviewed_by
_staff_cod
e,reviewed
_date,
reviewed_rule,natural_cost
_tax_amt,n
ocharge_co
de,
nocharge_notes,location_co
de,referen
ce_code,na
tural_cost
_amt,
natural_sell_amt,markup_pc
t,last_edi
t_user,
tax_code,post_ctrl_num,rej
ection_des
c,rejectio
n_advised_
flag,
activity_code,analysis_cod
e,activity
_type_code
, last_edit_user, getdate()
FROM deleted
-- Audit NEW record.
INSERT INTO cbf_audit_pawsxexp_deletes
(resource_code,period_end_
date,tran_
date,trx_d
etail_id ,
client_code,project_code, subproject_code, expense_code,
natural_cost_taxinc_rate,q
ty,reimbur
sement_cos
t_taxinc_a
mt,
mop_code,reimb_flag,nochar
ge_flag,re
ceipt_flag
,details,
posted_state,approved_stat
e,
data_source,approved_by_st
aff_code,
approved_date,batch_ctrl_n
um,manual_
entry_flag
,
clients_reference,project_
id,approve
d_rule,
created_date,created_user,
last_edit_
date,
reviewed_state,reviewed_by
_staff_cod
e,reviewed
_date,
reviewed_rule,natural_cost
_tax_amt,n
ocharge_co
de,
nocharge_notes,location_co
de,referen
ce_code,na
tural_cost
_amt,
natural_sell_amt,markup_pc
t,last_edi
t_user,
tax_code,post_ctrl_num,rej
ection_des
c,rejectio
n_advised_
flag,
activity_code,analysis_cod
e,activity
_type_code
, Change_User,change_date)
SELECT resource_code,period_end_d
ate,tran_d
ate,trx_de
tail_id ,
client_code,project_code, subproject_code, expense_code,
natural_cost_taxinc_rate,q
ty,reimbur
sement_cos
t_taxinc_a
mt,
mop_code,reimb_flag,nochar
ge_flag,re
ceipt_flag
,details,
posted_state,approved_stat
e,
data_source,approved_by_st
aff_code,
approved_date,batch_ctrl_n
um,manual_
entry_flag
,
clients_reference,project_
id,approve
d_rule,
created_date,created_user,
last_edit_
date,
reviewed_state,reviewed_by
_staff_cod
e,reviewed
_date,
reviewed_rule,natural_cost
_tax_amt,n
ocharge_co
de,
nocharge_notes,location_co
de,referen
ce_code,na
tural_cost
_amt,
natural_sell_amt,markup_pc
t,last_edi
t_user,
tax_code,post_ctrl_num,rej
ection_des
c,rejectio
n_advised_
flag,
activity_code,analysis_cod
e,activity
_type_code
,last_edit
_user, getdate()
FROM inserted
END
Start Free Trial