Advertisement

10.02.2007 at 08:11AM PDT, ID: 22866560
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.8

Need to stop one action from causing trigger to write to Audit table

Asked by mwrye in MS SQL Server

Tags: , , ,

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_Audit_tr    Script Date: 9/5/2007 8:24:42 AM ******/

CREATE TRIGGER [Update_for_Reject_Audit_tr]
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_detail_id ,
      client_code,project_code, subproject_code, expense_code,
      natural_cost_taxinc_rate,qty,reimbursement_cost_taxinc_amt,
      mop_code,reimb_flag,nocharge_flag,receipt_flag,details,
      posted_state,approved_state,
      data_source,approved_by_staff_code,
      approved_date,batch_ctrl_num,manual_entry_flag,
      clients_reference,project_id,approved_rule,
      created_date,created_user,last_edit_date,
      reviewed_state,reviewed_by_staff_code,reviewed_date,
      reviewed_rule,natural_cost_tax_amt,nocharge_code,
      nocharge_notes,location_code,reference_code,natural_cost_amt,
      natural_sell_amt,markup_pct,last_edit_user,tax_code,post_ctrl_num,
      rejection_desc,rejection_advised_flag,
      activity_code,analysis_code,activity_type_code, Change_User, change_date)
 
         SELECT resource_code,period_end_date,tran_date,trx_detail_id ,
      client_code,project_code, subproject_code, expense_code,
      natural_cost_taxinc_rate,qty,reimbursement_cost_taxinc_amt,
      mop_code,reimb_flag,nocharge_flag,receipt_flag,details,
      posted_state,approved_state,
      data_source,approved_by_staff_code,
      approved_date,batch_ctrl_num,manual_entry_flag,
      clients_reference,project_id,approved_rule,
      created_date,created_user,last_edit_date,
      reviewed_state,reviewed_by_staff_code,reviewed_date,
      reviewed_rule,natural_cost_tax_amt,nocharge_code,
      nocharge_notes,location_code,reference_code,natural_cost_amt,
      natural_sell_amt,markup_pct,last_edit_user,
      tax_code,post_ctrl_num,rejection_desc,rejection_advised_flag,
      activity_code,analysis_code,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_detail_id ,
      client_code,project_code, subproject_code, expense_code,
      natural_cost_taxinc_rate,qty,reimbursement_cost_taxinc_amt,
      mop_code,reimb_flag,nocharge_flag,receipt_flag,details,
      posted_state,approved_state,
      data_source,approved_by_staff_code,
      approved_date,batch_ctrl_num,manual_entry_flag,
      clients_reference,project_id,approved_rule,
      created_date,created_user,last_edit_date,
      reviewed_state,reviewed_by_staff_code,reviewed_date,
      reviewed_rule,natural_cost_tax_amt,nocharge_code,
      nocharge_notes,location_code,reference_code,natural_cost_amt,
      natural_sell_amt,markup_pct,last_edit_user,
      tax_code,post_ctrl_num,rejection_desc,rejection_advised_flag,
      activity_code,analysis_code,activity_type_code, Change_User,change_date)

      SELECT resource_code,period_end_date,tran_date,trx_detail_id ,
      client_code,project_code, subproject_code, expense_code,
      natural_cost_taxinc_rate,qty,reimbursement_cost_taxinc_amt,
      mop_code,reimb_flag,nocharge_flag,receipt_flag,details,
      posted_state,approved_state,
      data_source,approved_by_staff_code,
      approved_date,batch_ctrl_num,manual_entry_flag,
      clients_reference,project_id,approved_rule,
      created_date,created_user,last_edit_date,
      reviewed_state,reviewed_by_staff_code,reviewed_date,
      reviewed_rule,natural_cost_tax_amt,nocharge_code,
      nocharge_notes,location_code,reference_code,natural_cost_amt,
      natural_sell_amt,markup_pct,last_edit_user,
      tax_code,post_ctrl_num,rejection_desc,rejection_advised_flag,
      activity_code,analysis_code,activity_type_code,last_edit_user, getdate()
        FROM inserted
   END
Start Free Trial
[+][-]10.02.2007 at 08:33AM PDT, ID: 19999399

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.02.2007 at 09:37AM PDT, ID: 19999940

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: MS SQL Server
Tags: trigger, action, insert, sql
Sign Up Now!
Solution Provided By: ScottPletcher
Participating Experts: 2
Solution Grade: A
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_1_20070628