SQL Server Performance

How do I debug this Trigger?

Discussion in 'SQL Server 2005 T-SQL Performance Tuning' started by bulldogniner, Jun 3, 2008.

  1. bulldogniner New Member

    I am trying to create an audit table and I found a script that is supposed to accomplish this. Unfortunately, I don't know how to debug it. Here is the code it is trying to execute. How do I determine what is failing?
    insert CBRM_AUDIT (Type, TableName, PK, FieldName, OldValue, NewValue, UpdateDate, UserName) select
    'U','SYS_PRICINGASSN','<PRICINGID='+convert(varchar(100),coalesce(i.PRICINGID,d.PRICINGID))+'>'+'<REGIONID='+convert(varchar(100),coalesce(i.REGIONID,d.REGIONID))+'>','DESCRIPTION',convert(varchar(1000),d.DESCRIPTION),convert(varchar(1000),i.DESCRIPTION),'20080603 15:07:07:530','NT_AKARIGWA' from #ins i full outer join #del d on i.PRICINGID = d.PRICINGID and i.REGIONID = d.REGIONID where i.DESCRIPTION <> d.DESCRIPTION or (i.DESCRIPTION is null and d.DESCRIPTION is not null) or (i.DESCRIPTION is not null and d.DESCRIPTION is null)
  2. Luis Martin Moderator

    What is the error?
  3. Adriaan New Member

    Create temp tables to mimic the inserted and deleted snapshots. Insert the rows that you're expecting in both.
    Rewrite the trigger code to use the temp tables, then run the script to see what is going wrong.

Share This Page