Questions about triggers

  • Hi,
    First, I am having something really weird happening. I have a VB.Net form that has displays data from the database and allows users to update fields on the form.
    Tere is a trigger on the tables associated with the form that on an update will insert the changed value in a table for change tracking purposes. Most of the time this works great.
    Hoewever somnetimes it will grab other pieces of data on the form, that was not changed and insert them into the change table as well.
    Any ideas how I can find out why this is happening.

    2nd question: 
    I have read that I can do somethign like this to see the deleted and the inserted values,
    DECLARE @OldValue int, @NewValue int
      SELECT @OldValue = Column FROM DELETED
     SELECT @NewValue = Column  FROM INSERTED
    but I have not figured out how or when to use this. I tried putting it in the trigger but then the trigger does not work. 
    Any idea how I can see the values from the virtual tables.

    Thank you

  • itmasterw 60042 - Friday, December 7, 2018 6:44 AM

    Hi,
    First, I am having something really weird happening. I have a VB.Net form that has displays data from the database and allows users to update fields on the form.
    Tere is a trigger on the tables associated with the form that on an update will insert the changed value in a table for change tracking purposes. Most of the time this works great.
    Hoewever somnetimes it will grab other pieces of data on the form, that was not changed and insert them into the change table as well.
    Any ideas how I can find out why this is happening.

    2nd question: 
    I have read that I can do somethign like this to see the deleted and the inserted values,
    DECLARE @OldValue int, @NewValue int
      SELECT @OldValue = Column FROM DELETED
     SELECT @NewValue = Column  FROM INSERTED
    but I have not figured out how or when to use this. I tried putting it in the trigger but then the trigger does not work. 
    Any idea how I can see the values from the virtual tables.

    Thank you

    I think you need to provide the code in the trigger for us to diagnose this.

  • Sure, here is the trigger:
    USE [DMPCRU_Dev]
    GO
    /****** Object:  Trigger [dbo].[ChangeTrackingOnUpdateDebtorInfo]    Script Date: 12/7/2018 7:25:21 AM ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    ALTER TRIGGER [dbo].[ChangeTrackingOnUpdateDebtorInfo] ON [dbo].[DebtorInfo] AFTER UPDATE AS
    --<SCRIPT AUTOGENERATED BY UpdateChangeTracking sp!>
     IF UPDATE([account_type])
     INSERT INTO Changes
     (file_no, table_name, changed_from,
     changed_to,
     changed_column, created, createdby)
     SELECT i.file_no, 'DebtorInfo', ISNULL(CAST(d.[account_type] as varchar ), '<NULL>'),
     ISNULL(CAST(i.[account_type] as varchar ), '<NULL>'),
     '[account_type]', CURRENT_TIMESTAMP, suser_sname()
     FROM Inserted i
     LEFT OUTER JOIN Deleted d on i.file_no = d.file_no
     WHERE (  d.[account_type] <> i.[account_type]
      OR (d.[account_type] IS NULL AND i.[account_type] IS NOT NULL)
      OR (d.[account_type] IS NOT NULL AND i.[account_type] IS NULL)
      )
     IF UPDATE([accrued_interest])
     INSERT INTO Changes
     (file_no, table_name, changed_from,
     changed_to,
     changed_column, created, createdby)
     SELECT i.file_no, 'DebtorInfo', ISNULL(CAST(d.[accrued_interest] as varchar ), '<NULL>'),
     ISNULL(CAST(i.[accrued_interest] as varchar ), '<NULL>'),
     '[accrued_interest]', CURRENT_TIMESTAMP, suser_sname()
     FROM Inserted i
     LEFT OUTER JOIN Deleted d on i.file_no = d.file_no
     WHERE (  d.[accrued_interest] <> i.[accrued_interest]
      OR (d.[accrued_interest] IS NULL AND i.[accrued_interest] IS NOT NULL)
      OR (d.[accrued_interest] IS NOT NULL AND i.[accrued_interest] IS NULL)
      )
     IF UPDATE([acct_status])
     INSERT INTO Changes
     (file_no, table_name, changed_from,
     changed_to,
     changed_column, created, createdby)
     SELECT i.file_no, 'DebtorInfo', ISNULL(CAST(d.[acct_status] as varchar ), '<NULL>'),
     ISNULL(CAST(i.[acct_status] as varchar ), '<NULL>'),
     '[acct_status]', CURRENT_TIMESTAMP, suser_sname()
     FROM Inserted i
     LEFT OUTER JOIN Deleted d on i.file_no = d.file_no
     WHERE (  d.[acct_status] <> i.[acct_status]
      OR (d.[acct_status] IS NULL AND i.[acct_status] IS NOT NULL)
      OR (d.[acct_status] IS NOT NULL AND i.[acct_status] IS NULL)
      )
     IF UPDATE([add_1])
     INSERT INTO Changes
     (file_no, table_name, changed_from,
     changed_to,
     changed_column, created, createdby)
     SELECT i.file_no, 'DebtorInfo', ISNULL(CAST(d.[add_1] as varchar ), '<NULL>'),
     ISNULL(CAST(i.[add_1] as varchar ), '<NULL>'),
     '[add_1]', CURRENT_TIMESTAMP, suser_sname()
     FROM Inserted i
     LEFT OUTER JOIN Deleted d on i.file_no = d.file_no
     WHERE (  d.[add_1] <> i.[add_1]
      OR (d.[add_1] IS NULL AND i.[add_1] IS NOT NULL)
      OR (d.[add_1] IS NOT NULL AND i.[add_1] IS NULL)
      )
     IF UPDATE([add_2])
     INSERT INTO Changes
     (file_no, table_name, changed_from,
     changed_to,
     changed_column, created, createdby)
     SELECT i.file_no, 'DebtorInfo', ISNULL(CAST(d.[add_2] as varchar ), '<NULL>'),
     ISNULL(CAST(i.[add_2] as varchar ), '<NULL>'),
     '[add_2]', CURRENT_TIMESTAMP, suser_sname()
     FROM Inserted i
     LEFT OUTER JOIN Deleted d on i.file_no = d.file_no
     WHERE (  d.[add_2] <> i.[add_2]
      OR (d.[add_2] IS NULL AND i.[add_2] IS NOT NULL)
      OR (d.[add_2] IS NOT NULL AND i.[add_2] IS NULL)
      )
     IF UPDATE([adtl_ph])
     INSERT INTO Changes
     (file_no, table_name, changed_from,
     changed_to,
     changed_column, created, createdby)
     SELECT i.file_no, 'DebtorInfo', ISNULL(CAST(d.[adtl_ph] as varchar ), '<NULL>'),
     ISNULL(CAST(i.[adtl_ph] as varchar ), '<NULL>'),
     '[adtl_ph]', CURRENT_TIMESTAMP, suser_sname()
     FROM Inserted i
     LEFT OUTER JOIN Deleted d on i.file_no = d.file_no
     WHERE (  d.[adtl_ph] <> i.[adtl_ph]
      OR (d.[adtl_ph] IS NULL AND i.[adtl_ph] IS NOT NULL)
      OR (d.[adtl_ph] IS NOT NULL AND i.[adtl_ph] IS NULL)
      )
     IF UPDATE([bad_SF])
     INSERT INTO Changes
     (file_no, table_name, changed_from,
     changed_to,
     changed_column, created, createdby)
     SELECT i.file_no, 'DebtorInfo', ISNULL(CAST(d.[bad_SF] as varchar ), '<NULL>'),
     ISNULL(CAST(i.[bad_SF] as varchar ), '<NULL>'),
     '[bad_SF]', CURRENT_TIMESTAMP, suser_sname()
     FROM Inserted i
     LEFT OUTER JOIN Deleted d on i.file_no = d.file_no
     WHERE (  d.[bad_SF] <> i.[bad_SF]
      OR (d.[bad_SF] IS NULL AND i.[bad_SF] IS NOT NULL)
      OR (d.[bad_SF] IS NOT NULL AND i.[bad_SF] IS NULL)
      )
     IF UPDATE([bank_id])
     INSERT INTO Changes
     (file_no, table_name, changed_from,
     changed_to,
     changed_column, created, createdby)
     SELECT i.file_no, 'DebtorInfo', ISNULL(CAST(d.[bank_id] as varchar ), '<NULL>'),
     ISNULL(CAST(i.[bank_id] as varchar ), '<NULL>'),
     '[bank_id]', CURRENT_TIMESTAMP, suser_sname()
     FROM Inserted i
     LEFT OUTER JOIN Deleted d on i.file_no = d.file_no
     WHERE (  d.[bank_id] <> i.[bank_id]
      OR (d.[bank_id] IS NULL AND i.[bank_id] IS NOT NULL)
      OR (d.[bank_id] IS NOT NULL AND i.[bank_id] IS NULL)
      )
     IF UPDATE([bk_monitor])
     INSERT INTO Changes
     (file_no, table_name, changed_from,
     changed_to,
     changed_column, created, createdby)
     SELECT i.file_no, 'DebtorInfo', ISNULL(CAST(d.[bk_monitor] as varchar ), '<NULL>'),
     ISNULL(CAST(i.[bk_monitor] as varchar ), '<NULL>'),
     '[bk_monitor]', CURRENT_TIMESTAMP, suser_sname()
     FROM Inserted i
     LEFT OUTER JOIN Deleted d on i.file_no = d.file_no
     WHERE (  d.[bk_monitor] <> i.[bk_monitor]
      OR (d.[bk_monitor] IS NULL AND i.[bk_monitor] IS NOT NULL)
      OR (d.[bk_monitor] IS NOT NULL AND i.[bk_monitor] IS NULL)
      )
     IF UPDATE([brand])
     INSERT INTO Changes
     (file_no, table_name, changed_from,
     changed_to,
     changed_column, created, createdby)
     SELECT i.file_no, 'DebtorInfo', ISNULL(CAST(d.[brand] as varchar ), '<NULL>'),
     ISNULL(CAST(i.[brand] as varchar ), '<NULL>'),
     '[brand]', CURRENT_TIMESTAMP, suser_sname()
     FROM Inserted i
     LEFT OUTER JOIN Deleted d on i.file_no = d.file_no
     WHERE (  d.[brand] <> i.[brand]
      OR (d.[brand] IS NULL AND i.[brand] IS NOT NULL)
      OR (d.[brand] IS NOT NULL AND i.[brand] IS NULL)
      )
     IF UPDATE([card_exp_date])
     INSERT INTO Changes
     (file_no, table_name, changed_from,
     changed_to,
     changed_column, created, createdby)
     SELECT i.file_no, 'DebtorInfo', ISNULL(CAST(d.[card_exp_date] as varchar ), '<NULL>'),
     ISNULL(CAST(i.[card_exp_date] as varchar ), '<NULL>'),
     '[card_exp_date]', CURRENT_TIMESTAMP, suser_sname()
     FROM Inserted i
     LEFT OUTER JOIN Deleted d on i.file_no = d.file_no
     WHERE (  d.[card_exp_date] <> i.[card_exp_date]
      OR (d.[card_exp_date] IS NULL AND i.[card_exp_date] IS NOT NULL)
      OR (d.[card_exp_date] IS NOT NULL AND i.[card_exp_date] IS NULL)
      )
     IF UPDATE([card_type])
     INSERT INTO Changes
     (file_no, table_name, changed_from,
     changed_to,
     changed_column, created, createdby)
     SELECT i.file_no, 'DebtorInfo', ISNULL(CAST(d.[card_type] as varchar ), '<NULL>'),
     ISNULL(CAST(i.[card_type] as varchar ), '<NULL>'),
     '[card_type]', CURRENT_TIMESTAMP, suser_sname()
     FROM Inserted i
     LEFT OUTER JOIN Deleted d on i.file_no = d.file_no
     WHERE (  d.[card_type] <> i.[card_type]
      OR (d.[card_type] IS NULL AND i.[card_type] IS NOT NULL)
      OR (d.[card_type] IS NOT NULL AND i.[card_type] IS NULL)
      )
     IF UPDATE([cbr_cc])
     INSERT INTO Changes
     (file_no, table_name, changed_from,
     changed_to,
     changed_column, created, createdby)
     SELECT i.file_no, 'DebtorInfo', ISNULL(CAST(d.[cbr_cc] as varchar ), '<NULL>'),
     ISNULL(CAST(i.[cbr_cc] as varchar ), '<NULL>'),
     '[cbr_cc]', CURRENT_TIMESTAMP, suser_sname()
     FROM Inserted i
     LEFT OUTER JOIN Deleted d on i.file_no = d.file_no
     WHERE (  d.[cbr_cc] <> i.[cbr_cc]
      OR (d.[cbr_cc] IS NULL AND i.[cbr_cc] IS NOT NULL)
      OR (d.[cbr_cc] IS NOT NULL AND i.[cbr_cc] IS NULL)
      )
                                                                                                                                                                                                                                                                                                                                                   IF UPDATE([cbr_oos_date])
     INSERT INTO Changes
     (file_no, table_name, changed_from,
     changed_to,
     changed_column, created, createdby)
     SELECT i.file_no, 'DebtorInfo', ISNULL(CAST(d.[cbr_oos_date] as varchar ), '<NULL>'),
     ISNULL(CAST(i.[cbr_oos_date] as varchar ), '<NULL>'),
     '[cbr_oos_date]', CURRENT_TIMESTAMP, suser_sname()
     FROM Inserted i
     LEFT OUTER JOIN Deleted d on i.file_no = d.file_no
     WHERE (  d.[cbr_oos_date] <> i.[cbr_oos_date]
      OR (d.[cbr_oos_date] IS NULL AND i.[cbr_oos_date] IS NOT NULL)
      OR (d.[cbr_oos_date] IS NOT NULL AND i.[cbr_oos_date] IS NULL)
      )
     IF UPDATE([cell_ph])
     INSERT INTO Changes
     (file_no, table_name, changed_from,
     changed_to,
     changed_column, created, createdby)
     SELECT i.file_no, 'DebtorInfo', ISNULL(CAST(d.[cell_ph] as varchar ), '<NULL>'),
     ISNULL(CAST(i.[cell_ph] as varchar ), '<NULL>'),
     '[cell_ph]', CURRENT_TIMESTAMP, suser_sname()
     FROM Inserted i
     LEFT OUTER JOIN Deleted d on i.file_no = d.file_no
     WHERE (  d.[cell_ph] <> i.[cell_ph]
      OR (d.[cell_ph] IS NULL AND i.[cell_ph] IS NOT NULL)
      OR (d.[cell_ph] IS NOT NULL AND i.[cell_ph] IS NULL)
      )
     IF UPDATE([city])
     INSERT INTO Changes
     (file_no, table_name, changed_from,
     changed_to,
     changed_column, created, createdby)
     SELECT i.file_no, 'DebtorInfo', ISNULL(CAST(d.[city] as varchar ), '<NULL>'),
     ISNULL(CAST(i.[city] as varchar ), '<NULL>'),
     '[city]', CURRENT_TIMESTAMP, suser_sname()
     FROM Inserted i
     LEFT OUTER JOIN Deleted d on i.file_no = d.file_no
     WHERE (  d.[city] <> i.[city]
      OR (d.[city] IS NULL AND i.[city] IS NOT NULL)
      OR (d.[city] IS NOT NULL AND i.[city] IS NULL)
      )
     IF UPDATE([client_code])
     INSERT INTO Changes
     (file_no, table_name, changed_from,
     changed_to,
     changed_column, created, createdby)
     SELECT i.file_no, 'DebtorInfo', ISNULL(CAST(d.[client_code] as varchar ), '<NULL>'),
     ISNULL(CAST(i.[client_code] as varchar ), '<NULL>'),
     '[client_code]', CURRENT_TIMESTAMP, suser_sname()
     FROM Inserted i
     LEFT OUTER JOIN Deleted d on i.file_no = d.file_no
     WHERE (  d.[client_code] <> i.[client_code]
      OR (d.[client_code] IS NULL AND i.[client_code] IS NOT NULL)
      OR (d.[client_code] IS NOT NULL AND i.[client_code] IS NULL)
      )
     IF UPDATE([Client_PlacementID])
     INSERT INTO Changes
     (file_no, table_name, changed_from,
     changed_to,
     changed_column, created, createdby)
     SELECT i.file_no, 'DebtorInfo', ISNULL(CAST(d.[Client_PlacementID] as varchar ), '<NULL>'),
     ISNULL(CAST(i.[Client_PlacementID] as varchar ), '<NULL>'),
     '[Client_PlacementID]', CURRENT_TIMESTAMP, suser_sname()
     FROM Inserted i
     LEFT OUTER JOIN Deleted d on i.file_no = d.file_no
     WHERE (  d.[Client_PlacementID] <> i.[Client_PlacementID]
      OR (d.[Client_PlacementID] IS NULL AND i.[Client_PlacementID] IS NOT NULL)
      OR (d.[Client_PlacementID] IS NOT NULL AND i.[Client_PlacementID] IS NULL)
      )
     IF UPDATE([Client_Pur_ID])
     INSERT INTO Changes
     (file_no, table_name, changed_from,
     changed_to,
     changed_column, created, createdby)
     SELECT i.file_no, 'DebtorInfo', ISNULL(CAST(d.[Client_Pur_ID] as varchar ), '<NULL>'),
     ISNULL(CAST(i.[Client_Pur_ID] as varchar ), '<NULL>'),
     '[Client_Pur_ID]', CURRENT_TIMESTAMP, suser_sname()
     FROM Inserted i
     LEFT OUTER JOIN Deleted d on i.file_no = d.file_no
     WHERE (  d.[Client_Pur_ID] <> i.[Client_Pur_ID]
      OR (d.[Client_Pur_ID] IS NULL AND i.[Client_Pur_ID] IS NOT NULL)
      OR (d.[Client_Pur_ID] IS NOT NULL AND i.[Client_Pur_ID] IS NULL)
      )
     IF UPDATE([client_recall_process])
     INSERT INTO Changes
     (file_no, table_name, changed_from,
     changed_to,
     changed_column, created, createdby)
     SELECT i.file_no, 'DebtorInfo', ISNULL(CAST(d.[client_recall_process] as varchar ), '<NULL>'),
     ISNULL(CAST(i.[client_recall_process] as varchar ), '<NULL>'),
     '[client_recall_process]', CURRENT_TIMESTAMP, suser_sname()
     FROM Inserted i
     LEFT OUTER JOIN Deleted d on i.file_no = d.file_no
     WHERE (  d.[client_recall_process] <> i.[client_recall_process]
      OR (d.[client_recall_process] IS NULL AND i.[client_recall_process] IS NOT NULL)
      OR (d.[client_recall_process] IS NOT NULL AND i.[client_recall_process] IS NULL)
      )
     IF UPDATE([Client_Status])
     INSERT INTO Changes
     (file_no, table_name, changed_from,
     changed_to,
     changed_column, created, createdby)
     SELECT i.file_no, 'DebtorInfo', ISNULL(CAST(d.[Client_Status] as varchar ), '<NULL>'),
     ISNULL(CAST(i.[Client_Status] as varchar ), '<NULL>'),
     '[Client_Status]', CURRENT_TIMESTAMP, suser_sname()
     FROM Inserted i
     LEFT OUTER JOIN Deleted d on i.file_no = d.file_no
     WHERE (  d.[Client_Status] <> i.[Client_Status]
      OR (d.[Client_Status] IS NULL AND i.[Client_Status] IS NOT NULL)
      OR (d.[Client_Status] IS NOT NULL AND i.[Client_Status] IS NULL)
      )
     IF UPDATE([co_acct_no])
     INSERT INTO Changes
     (file_no, table_name, changed_from,
     changed_to,
     changed_column, created, createdby)
     SELECT i.file_no, 'DebtorInfo', ISNULL(CAST(d.[co_acct_no] as varchar ), '<NULL>'),
     ISNULL(CAST(i.[co_acct_no] as varchar ), '<NULL>'),
     '[co_acct_no]', CURRENT_TIMESTAMP, suser_sname()
     FROM Inserted i
     LEFT OUTER JOIN Deleted d on i.file_no = d.file_no
     WHERE (  d.[co_acct_no] <> i.[co_acct_no]
      OR (d.[co_acct_no] IS NULL AND i.[co_acct_no] IS NOT NULL)
      OR (d.[co_acct_no] IS NOT NULL AND i.[co_acct_no] IS NULL)
      )
     IF UPDATE([co_balance])
     INSERT INTO Changes
     (file_no, table_name, changed_from,
     changed_to,
     changed_column, created, createdby)
     SELECT i.file_no, 'DebtorInfo', ISNULL(CAST(d.[co_balance] as varchar ), '<NULL>'),
     ISNULL(CAST(i.[co_balance] as varchar ), '<NULL>'),
     '[co_balance]', CURRENT_TIMESTAMP, suser_sname()
     FROM Inserted i
     LEFT OUTER JOIN Deleted d on i.file_no = d.file_no
     WHERE (  d.[co_balance] <> i.[co_balance]
      OR (d.[co_balance] IS NULL AND i.[co_balance] IS NOT NULL)
      OR (d.[co_balance] IS NOT NULL AND i.[co_balance] IS NULL)
      )
                                                                                                                                                                                                                                                                                                                                                   IF UPDATE([co_date])
     INSERT INTO Changes
     (file_no, table_name, changed_from,
     changed_to,
     changed_column, created, createdby)
     SELECT i.file_no, 'DebtorInfo', ISNULL(CAST(d.[co_date] as varchar ), '<NULL>'),
     ISNULL(CAST(i.[co_date] as varchar ), '<NULL>'),
     '[co_date]', CURRENT_TIMESTAMP, suser_sname()
     FROM Inserted i
     LEFT OUTER JOIN Deleted d on i.file_no = d.file_no
     WHERE (  d.[co_date] <> i.[co_date]
      OR (d.[co_date] IS NULL AND i.[co_date] IS NOT NULL)
      OR (d.[co_date] IS NOT NULL AND i.[co_date] IS NULL)
      )
     IF UPDATE([credit_bureau_rpt])
     INSERT INTO Changes
     (file_no, table_name, changed_from,
     changed_to,
     changed_column, created, createdby)
     SELECT i.file_no, 'DebtorInfo', ISNULL(CAST(d.[credit_bureau_rpt] as varchar ), '<NULL>'),
     ISNULL(CAST(i.[credit_bureau_rpt] as varchar ), '<NULL>'),
     '[credit_bureau_rpt]', CURRENT_TIMESTAMP, suser_sname()
     FROM Inserted i
     LEFT OUTER JOIN Deleted d on i.file_no = d.file_no
     WHERE (  d.[credit_bureau_rpt] <> i.[credit_bureau_rpt]
      OR (d.[credit_bureau_rpt] IS NULL AND i.[credit_bureau_rpt] IS NOT NULL)
      OR (d.[credit_bureau_rpt] IS NOT NULL AND i.[credit_bureau_rpt] IS NULL)
      )
     IF UPDATE([customer_id])
     INSERT INTO Changes
     (file_no, table_name, changed_from,
     changed_to,
     changed_column, created, createdby)
     SELECT i.file_no, 'DebtorInfo', ISNULL(CAST(d.[customer_id] as varchar ), '<NULL>'),
     ISNULL(CAST(i.[customer_id] as varchar ), '<NULL>'),
     '[customer_id]', CURRENT_TIMESTAMP, suser_sname()
     FROM Inserted i
     LEFT OUTER JOIN Deleted d on i.file_no = d.file_no
     WHERE (  d.[customer_id] <> i.[customer_id]
      OR (d.[customer_id] IS NULL AND i.[customer_id] IS NOT NULL)
      OR (d.[customer_id] IS NOT NULL AND i.[customer_id] IS NULL)
      )
     IF UPDATE([DEBTOR_INDEX])
     INSERT INTO Changes
     (file_no, table_name, changed_from,
     changed_to,
     changed_column, created, createdby)
     SELECT i.file_no, 'DebtorInfo', ISNULL(CAST(d.[DEBTOR_INDEX] as varchar ), '<NULL>'),
     ISNULL(CAST(i.[DEBTOR_INDEX] as varchar ), '<NULL>'),
     '[DEBTOR_INDEX]', CURRENT_TIMESTAMP, suser_sname()
     FROM Inserted i
     LEFT OUTER JOIN Deleted d on i.file_no = d.file_no
     WHERE (  d.[DEBTOR_INDEX] <> i.[DEBTOR_INDEX]
      OR (d.[DEBTOR_INDEX] IS NULL AND i.[DEBTOR_INDEX] IS NOT NULL)
      OR (d.[DEBTOR_INDEX] IS NOT NULL AND i.[DEBTOR_INDEX] IS NULL)
      )
     IF UPDATE([del_date])
     INSERT INTO Changes
     (file_no, table_name, changed_from,
     changed_to,
     changed_column, created, createdby)
     SELECT i.file_no, 'DebtorInfo', ISNULL(CAST(d.[del_date] as varchar ), '<NULL>'),
     ISNULL(CAST(i.[del_date] as varchar ), '<NULL>'),
     '[del_date]', CURRENT_TIMESTAMP, suser_sname()
     FROM Inserted i
     LEFT OUTER JOIN Deleted d on i.file_no = d.file_no
     WHERE (  d.[del_date] <> i.[del_date]
      OR (d.[del_date] IS NULL AND i.[del_date] IS NOT NULL)
      OR (d.[del_date] IS NOT NULL AND i.[del_date] IS NULL)
      )
     IF UPDATE([descrip])
     INSERT INTO Changes
     (file_no, table_name, changed_from,
     changed_to,
     changed_column, created, createdby)
     SELECT i.file_no, 'DebtorInfo', ISNULL(CAST(d.[descrip] as varchar ), '<NULL>'),
     ISNULL(CAST(i.[descrip] as varchar ), '<NULL>'),
     '[descrip]', CURRENT_TIMESTAMP, suser_sname()
     FROM Inserted i
     LEFT OUTER JOIN Deleted d on i.file_no = d.file_no
     WHERE (  d.[descrip] <> i.[descrip]
      OR (d.[descrip] IS NULL AND i.[descrip] IS NOT NULL)
      OR (d.[descrip] IS NOT NULL AND i.[descrip] IS NULL)
      )
     IF UPDATE([desk_no])
     INSERT INTO Changes
     (file_no, table_name, changed_from,
     changed_to,
     changed_column, created, createdby)
     SELECT i.file_no, 'DebtorInfo', ISNULL(CAST(d.[desk_no] as varchar ), '<NULL>'),
     ISNULL(CAST(i.[desk_no] as varchar ), '<NULL>'),
     '[desk_no]', CURRENT_TIMESTAMP, suser_sname()
     FROM Inserted i
     LEFT OUTER JOIN Deleted d on i.file_no = d.file_no
     WHERE (  d.[desk_no] <> i.[desk_no]
      OR (d.[desk_no] IS NULL AND i.[desk_no] IS NOT NULL)
      OR (d.[desk_no] IS NOT NULL AND i.[desk_no] IS NULL)
      )
     IF UPDATE([dob])
     INSERT INTO Changes
     (file_no, table_name, changed_from,
     changed_to,
     changed_column, created, createdby)
     SELECT i.file_no, 'DebtorInfo', ISNULL(CAST(d.[dob] as varchar ), '<NULL>'),
     ISNULL(CAST(i.[dob] as varchar ), '<NULL>'),
     '[dob]', CURRENT_TIMESTAMP, suser_sname()
     FROM Inserted i
     LEFT OUTER JOIN Deleted d on i.file_no = d.file_no
     WHERE (  d.[dob] <> i.[dob]
      OR (d.[dob] IS NULL AND i.[dob] IS NOT NULL)
      OR (d.[dob] IS NOT NULL AND i.[dob] IS NULL)
      )
     IF UPDATE([dtr1_email])
     INSERT INTO Changes
     (file_no, table_name, changed_from,
     changed_to,
     changed_column, created, createdby)
     SELECT i.file_no, 'DebtorInfo', ISNULL(CAST(d.[dtr1_email] as varchar ), '<NULL>'),
     ISNULL(CAST(i.[dtr1_email] as varchar ), '<NULL>'),
     '[dtr1_email]', CURRENT_TIMESTAMP, suser_sname()
     FROM Inserted i
     LEFT OUTER JOIN Deleted d on i.file_no = d.file_no
     WHERE (  d.[dtr1_email] <> i.[dtr1_email]
      OR (d.[dtr1_email] IS NULL AND i.[dtr1_email] IS NOT NULL)
      OR (d.[dtr1_email] IS NOT NULL AND i.[dtr1_email] IS NULL)
      )
     IF UPDATE([emergency])
     INSERT INTO Changes
     (file_no, table_name, changed_from,
     changed_to,
     changed_column, created, createdby)
     SELECT i.file_no, 'DebtorInfo', ISNULL(CAST(d.[emergency] as varchar ), '<NULL>'),
     ISNULL(CAST(i.[emergency] as varchar ), '<NULL>'),
     '[emergency]', CURRENT_TIMESTAMP, suser_sname()
     FROM Inserted i
     LEFT OUTER JOIN Deleted d on i.file_no = d.file_no
     WHERE (  d.[emergency] <> i.[emergency]
      OR (d.[emergency] IS NULL AND i.[emergency] IS NOT NULL)
      OR (d.[emergency] IS NOT NULL AND i.[emergency] IS NULL)
      )
     IF UPDATE([empl_ph])
     INSERT INTO Changes
     (file_no, table_name, changed_from,
     changed_to,
     changed_column, created, createdby)
     SELECT i.file_no, 'DebtorInfo', ISNULL(CAST(d.[empl_ph] as varchar ), '<NULL>'),
     ISNULL(CAST(i.[empl_ph] as varchar ), '<NULL>'),
     '[empl_ph]', CURRENT_TIMESTAMP, suser_sname()
     FROM Inserted i
     LEFT OUTER JOIN Deleted d on i.file_no = d.file_no
     WHERE (  d.[empl_ph] <> i.[empl_ph]
      OR (d.[empl_ph] IS NULL AND i.[empl_ph] IS NOT NULL)
      OR (d.[empl_ph] IS NOT NULL AND i.[empl_ph] IS NULL)
      )
                                                                                                                                                                                                                                                                                                                                                   IF UPDATE([file_no])
     INSERT INTO Changes
     (file_no, table_name, changed_from,
     changed_to,
     changed_column, created, createdby)
     SELECT i.file_no, 'DebtorInfo', ISNULL(CAST(d.[file_no] as varchar ), '<NULL>'),
     ISNULL(CAST(i.[file_no] as varchar ), '<NULL>'),
     '[file_no]', CURRENT_TIMESTAMP, suser_sname()
     FROM Inserted i
     LEFT OUTER JOIN Deleted d on i.file_no = d.file_no
     WHERE (  d.[file_no] <> i.[file_no]
      OR (d.[file_no] IS NULL AND i.[file_no] IS NOT NULL)
      OR (d.[file_no] IS NOT NULL AND i.[file_no] IS NULL)
      )
     IF UPDATE([first_name])
     INSERT INTO Changes
     (file_no, table_name, changed_from,
     changed_to,
     changed_column, created, createdby)
     SELECT i.file_no, 'DebtorInfo', ISNULL(CAST(d.[first_name] as varchar ), '<NULL>'),
     ISNULL(CAST(i.[first_name] as varchar ), '<NULL>'),
     '[first_name]', CURRENT_TIMESTAMP, suser_sname()
     FROM Inserted i
     LEFT OUTER JOIN Deleted d on i.file_no = d.file_no
     WHERE (  d.[first_name] <> i.[first_name]
      OR (d.[first_name] IS NULL AND i.[first_name] IS NOT NULL)
      OR (d.[first_name] IS NOT NULL AND i.[first_name] IS NULL)
      )
     IF UPDATE([home_ph])
     INSERT INTO Changes
     (file_no, table_name, changed_from,
     changed_to,
     changed_column, created, createdby)
     SELECT i.file_no, 'DebtorInfo', ISNULL(CAST(d.[home_ph] as varchar ), '<NULL>'),
     ISNULL(CAST(i.[home_ph] as varchar ), '<NULL>'),
     '[home_ph]', CURRENT_TIMESTAMP, suser_sname()
     FROM Inserted i
     LEFT OUTER JOIN Deleted d on i.file_no = d.file_no
     WHERE (  d.[home_ph] <> i.[home_ph]
      OR (d.[home_ph] IS NULL AND i.[home_ph] IS NOT NULL)
      OR (d.[home_ph] IS NOT NULL AND i.[home_ph] IS NULL)
      )
     IF UPDATE([judgment_balance])
     INSERT INTO Changes
     (file_no, table_name, changed_from,
     changed_to,
     changed_column, created, createdby)
     SELECT i.file_no, 'DebtorInfo', ISNULL(CAST(d.[judgment_balance] as varchar ), '<NULL>'),
     ISNULL(CAST(i.[judgment_balance] as varchar ), '<NULL>'),
     '[judgment_balance]', CURRENT_TIMESTAMP, suser_sname()
     FROM Inserted i
     LEFT OUTER JOIN Deleted d on i.file_no = d.file_no
     WHERE (  d.[judgment_balance] <> i.[judgment_balance]
      OR (d.[judgment_balance] IS NULL AND i.[judgment_balance] IS NOT NULL)
      OR (d.[judgment_balance] IS NOT NULL AND i.[judgment_balance] IS NULL)
      )
     IF UPDATE([K_Recall])
     INSERT INTO Changes
     (file_no, table_name, changed_from,
     changed_to,
     changed_column, created, createdby)
     SELECT i.file_no, 'DebtorInfo', ISNULL(CAST(d.[K_Recall] as varchar ), '<NULL>'),
     ISNULL(CAST(i.[K_Recall] as varchar ), '<NULL>'),
     '[K_Recall]', CURRENT_TIMESTAMP, suser_sname()
     FROM Inserted i
     LEFT OUTER JOIN Deleted d on i.file_no = d.file_no
     WHERE (  d.[K_Recall] <> i.[K_Recall]
      OR (d.[K_Recall] IS NULL AND i.[K_Recall] IS NOT NULL)
      OR (d.[K_Recall] IS NOT NULL AND i.[K_Recall] IS NULL)
      )
     IF UPDATE([last_bank_pay_amount])
     INSERT INTO Changes
     (file_no, table_name, changed_from,
     changed_to,
     changed_column, created, createdby)
     SELECT i.file_no, 'DebtorInfo', ISNULL(CAST(d.[last_bank_pay_amount] as varchar ), '<NULL>'),
     ISNULL(CAST(i.[last_bank_pay_amount] as varchar ), '<NULL>'),
     '[last_bank_pay_amount]', CURRENT_TIMESTAMP, suser_sname()
     FROM Inserted i
     LEFT OUTER JOIN Deleted d on i.file_no = d.file_no
     WHERE (  d.[last_bank_pay_amount] <> i.[last_bank_pay_amount]
      OR (d.[last_bank_pay_amount] IS NULL AND i.[last_bank_pay_amount] IS NOT NULL)
      OR (d.[last_bank_pay_amount] IS NOT NULL AND i.[last_bank_pay_amount] IS NULL)
      )
     IF UPDATE([last_bank_pay_date])
     INSERT INTO Changes
     (file_no, table_name, changed_from,
     changed_to,
     changed_column, created, createdby)
     SELECT i.file_no, 'DebtorInfo', ISNULL(CAST(d.[last_bank_pay_date] as varchar ), '<NULL>'),
     ISNULL(CAST(i.[last_bank_pay_date] as varchar ), '<NULL>'),
     '[last_bank_pay_date]', CURRENT_TIMESTAMP, suser_sname()
     FROM Inserted i
     LEFT OUTER JOIN Deleted d on i.file_no = d.file_no
     WHERE (  d.[last_bank_pay_date] <> i.[last_bank_pay_date]
      OR (d.[last_bank_pay_date] IS NULL AND i.[last_bank_pay_date] IS NOT NULL)
      OR (d.[last_bank_pay_date] IS NOT NULL AND i.[last_bank_pay_date] IS NULL)
      )
     IF UPDATE([last_name])
     INSERT INTO Changes
     (file_no, table_name, changed_from,
     changed_to,
     changed_column, created, createdby)
     SELECT i.file_no, 'DebtorInfo', ISNULL(CAST(d.[last_name] as varchar ), '<NULL>'),
     ISNULL(CAST(i.[last_name] as varchar ), '<NULL>'),
     '[last_name]', CURRENT_TIMESTAMP, suser_sname()
     FROM Inserted i
     LEFT OUTER JOIN Deleted d on i.file_no = d.file_no
     WHERE (  d.[last_name] <> i.[last_name]
      OR (d.[last_name] IS NULL AND i.[last_name] IS NOT NULL)
      OR (d.[last_name] IS NOT NULL AND i.[last_name] IS NULL)
      )
     IF UPDATE([last_pay_amount])
     INSERT INTO Changes
     (file_no, table_name, changed_from,
     changed_to,
     changed_column, created, createdby)
     SELECT i.file_no, 'DebtorInfo', ISNULL(CAST(d.[last_pay_amount] as varchar ), '<NULL>'),
     ISNULL(CAST(i.[last_pay_amount] as varchar ), '<NULL>'),
     '[last_pay_amount]', CURRENT_TIMESTAMP, suser_sname()
     FROM Inserted i
     LEFT OUTER JOIN Deleted d on i.file_no = d.file_no
     WHERE (  d.[last_pay_amount] <> i.[last_pay_amount]
      OR (d.[last_pay_amount] IS NULL AND i.[last_pay_amount] IS NOT NULL)
      OR (d.[last_pay_amount] IS NOT NULL AND i.[last_pay_amount] IS NULL)
      )
     IF UPDATE([last_pay_date])
     INSERT INTO Changes
     (file_no, table_name, changed_from,
     changed_to,
     changed_column, created, createdby)
     SELECT i.file_no, 'DebtorInfo', ISNULL(CAST(d.[last_pay_date] as varchar ), '<NULL>'),
     ISNULL(CAST(i.[last_pay_date] as varchar ), '<NULL>'),
     '[last_pay_date]', CURRENT_TIMESTAMP, suser_sname()
     FROM Inserted i
     LEFT OUTER JOIN Deleted d on i.file_no = d.file_no
     WHERE (  d.[last_pay_date] <> i.[last_pay_date]
      OR (d.[last_pay_date] IS NULL AND i.[last_pay_date] IS NOT NULL)
      OR (d.[last_pay_date] IS NOT NULL AND i.[last_pay_date] IS NULL)
      )
                                                                                                                                                                                                                                                                                                                                                   IF UPDATE([legal_status])
     INSERT INTO Changes
     (file_no, table_name, changed_from,
     changed_to,
     changed_column, created, createdby)
     SELECT i.file_no, 'DebtorInfo', ISNULL(CAST(d.[legal_status] as varchar ), '<NULL>'),
     ISNULL(CAST(i.[legal_status] as varchar ), '<NULL>'),
     '[legal_status]', CURRENT_TIMESTAMP, suser_sname()
     FROM Inserted i
     LEFT OUTER JOIN Deleted d on i.file_no = d.file_no
     WHERE (  d.[legal_status] <> i.[legal_status]
      OR (d.[legal_status] IS NULL AND i.[legal_status] IS NOT NULL)
      OR (d.[legal_status] IS NOT NULL AND i.[legal_status] IS NULL)
      )
     IF UPDATE([management_company])
     INSERT INTO Changes
     (file_no, table_name, changed_from,
     changed_to,
     changed_column, created, createdby)
     SELECT i.file_no, 'DebtorInfo', ISNULL(CAST(d.[management_company] as varchar ), '<NULL>'),
     ISNULL(CAST(i.[management_company] as varchar ), '<NULL>'),
     '[management_company]', CURRENT_TIMESTAMP, suser_sname()
     FROM Inserted i
     LEFT OUTER JOIN Deleted d on i.file_no = d.file_no
     WHERE (  d.[management_company] <> i.[management_company]
      OR (d.[management_company] IS NULL AND i.[management_company] IS NOT NULL)
      OR (d.[management_company] IS NOT NULL AND i.[management_company] IS NULL)
      )
     IF UPDATE([MC_Change_Date])
     INSERT INTO Changes
     (file_no, table_name, changed_from,
     changed_to,
     changed_column, created, createdby)
     SELECT i.file_no, 'DebtorInfo', ISNULL(CAST(d.[MC_Change_Date] as varchar ), '<NULL>'),
     ISNULL(CAST(i.[MC_Change_Date] as varchar ), '<NULL>'),
     '[MC_Change_Date]', CURRENT_TIMESTAMP, suser_sname()
     FROM Inserted i
     LEFT OUTER JOIN Deleted d on i.file_no = d.file_no
     WHERE (  d.[MC_Change_Date] <> i.[MC_Change_Date]
      OR (d.[MC_Change_Date] IS NULL AND i.[MC_Change_Date] IS NOT NULL)
      OR (d.[MC_Change_Date] IS NOT NULL AND i.[MC_Change_Date] IS NULL)
      )
     IF UPDATE([media_req])
     INSERT INTO Changes
     (file_no, table_name, changed_from,
     changed_to,
     changed_column, created, createdby)
     SELECT i.file_no, 'DebtorInfo', ISNULL(CAST(d.[media_req] as varchar ), '<NULL>'),
     ISNULL(CAST(i.[media_req] as varchar ), '<NULL>'),
     '[media_req]', CURRENT_TIMESTAMP, suser_sname()
     FROM Inserted i
     LEFT OUTER JOIN Deleted d on i.file_no = d.file_no
     WHERE (  d.[media_req] <> i.[media_req]
      OR (d.[media_req] IS NULL AND i.[media_req] IS NOT NULL)
      OR (d.[media_req] IS NOT NULL AND i.[media_req] IS NULL)
      )
     IF UPDATE([New_Recall_Process])
     INSERT INTO Changes
     (file_no, table_name, changed_from,
     changed_to,
     changed_column, created, createdby)
     SELECT i.file_no, 'DebtorInfo', ISNULL(CAST(d.[New_Recall_Process] as varchar ), '<NULL>'),
     ISNULL(CAST(i.[New_Recall_Process] as varchar ), '<NULL>'),
     '[New_Recall_Process]', CURRENT_TIMESTAMP, suser_sname()
     FROM Inserted i
     LEFT OUTER JOIN Deleted d on i.file_no = d.file_no
     WHERE (  d.[New_Recall_Process] <> i.[New_Recall_Process]
      OR (d.[New_Recall_Process] IS NULL AND i.[New_Recall_Process] IS NOT NULL)
      OR (d.[New_Recall_Process] IS NOT NULL AND i.[New_Recall_Process] IS NULL)
      )
     IF UPDATE([NK_Recall])
     INSERT INTO Changes
     (file_no, table_name, changed_from,
     changed_to,
     changed_column, created, createdby)
     SELECT i.file_no, 'DebtorInfo', ISNULL(CAST(d.[NK_Recall] as varchar ), '<NULL>'),
     ISNULL(CAST(i.[NK_Recall] as varchar ), '<NULL>'),
     '[NK_Recall]', CURRENT_TIMESTAMP, suser_sname()
     FROM Inserted i
     LEFT OUTER JOIN Deleted d on i.file_no = d.file_no
     WHERE (  d.[NK_Recall] <> i.[NK_Recall]
      OR (d.[NK_Recall] IS NULL AND i.[NK_Recall] IS NOT NULL)
      OR (d.[NK_Recall] IS NOT NULL AND i.[NK_Recall] IS NULL)
      )
     IF UPDATE([OneOff_Recall_Process])
     INSERT INTO Changes
     (file_no, table_name, changed_from,
     changed_to,
     changed_column, created, createdby)
     SELECT i.file_no, 'DebtorInfo', ISNULL(CAST(d.[OneOff_Recall_Process] as varchar ), '<NULL>'),
     ISNULL(CAST(i.[OneOff_Recall_Process] as varchar ), '<NULL>'),
     '[OneOff_Recall_Process]', CURRENT_TIMESTAMP, suser_sname()
     FROM Inserted i
     LEFT OUTER JOIN Deleted d on i.file_no = d.file_no
     WHERE (  d.[OneOff_Recall_Process] <> i.[OneOff_Recall_Process]
      OR (d.[OneOff_Recall_Process] IS NULL AND i.[OneOff_Recall_Process] IS NOT NULL)
      OR (d.[OneOff_Recall_Process] IS NOT NULL AND i.[OneOff_Recall_Process] IS NULL)
      )
     IF UPDATE([oos])
     INSERT INTO Changes
     (file_no, table_name, changed_from,
     changed_to,
     changed_column, created, createdby)
     SELECT i.file_no, 'DebtorInfo', ISNULL(CAST(d.[oos] as varchar ), '<NULL>'),
     ISNULL(CAST(i.[oos] as varchar ), '<NULL>'),
     '[oos]', CURRENT_TIMESTAMP, suser_sname()
     FROM Inserted i
     LEFT OUTER JOIN Deleted d on i.file_no = d.file_no
     WHERE (  d.[oos] <> i.[oos]
      OR (d.[oos] IS NULL AND i.[oos] IS NOT NULL)
      OR (d.[oos] IS NOT NULL AND i.[oos] IS NULL)
      )
     IF UPDATE([oos_date])
     INSERT INTO Changes
     (file_no, table_name, changed_from,
     changed_to,
     changed_column, created, createdby)
     SELECT i.file_no, 'DebtorInfo', ISNULL(CAST(d.[oos_date] as varchar ), '<NULL>'),
     ISNULL(CAST(i.[oos_date] as varchar ), '<NULL>'),
     '[oos_date]', CURRENT_TIMESTAMP, suser_sname()
     FROM Inserted i
     LEFT OUTER JOIN Deleted d on i.file_no = d.file_no
     WHERE (  d.[oos_date] <> i.[oos_date]
      OR (d.[oos_date] IS NULL AND i.[oos_date] IS NOT NULL)
      OR (d.[oos_date] IS NOT NULL AND i.[oos_date] IS NULL)
      )
     IF UPDATE([open_date])
     INSERT INTO Changes
     (file_no, table_name, changed_from,
     changed_to,
     changed_column, created, createdby)
     SELECT i.file_no, 'DebtorInfo', ISNULL(CAST(d.[open_date] as varchar ), '<NULL>'),
     ISNULL(CAST(i.[open_date] as varchar ), '<NULL>'),
     '[open_date]', CURRENT_TIMESTAMP, suser_sname()
     FROM Inserted i
     LEFT OUTER JOIN Deleted d on i.file_no = d.file_no
     WHERE (  d.[open_date] <> i.[open_date]
      OR (d.[open_date] IS NULL AND i.[open_date] IS NOT NULL)
      OR (d.[open_date] IS NOT NULL AND i.[open_date] IS NULL)
      )
                                                                                                                                                                                                                                                                                                                                                   IF UPDATE([orig_acct_no])
     INSERT INTO Changes
     (file_no, table_name, changed_from,
     changed_to,
     changed_column, created, createdby)
     SELECT i.file_no, 'DebtorInfo', ISNULL(CAST(d.[orig_acct_no] as varchar ), '<NULL>'),
     ISNULL(CAST(i.[orig_acct_no] as varchar ), '<NULL>'),
     '[orig_acct_no]', CURRENT_TIMESTAMP, suser_sname()
     FROM Inserted i
     LEFT OUTER JOIN Deleted d on i.file_no = d.file_no
     WHERE (  d.[orig_acct_no] <> i.[orig_acct_no]
      OR (d.[orig_acct_no] IS NULL AND i.[orig_acct_no] IS NOT NULL)
      OR (d.[orig_acct_no] IS NOT NULL AND i.[orig_acct_no] IS NULL)
      )
     IF UPDATE([orig_creditor])
     INSERT INTO Changes
     (file_no, table_name, changed_from,
     changed_to,
     changed_column, created, createdby)
     SELECT i.file_no, 'DebtorInfo', ISNULL(CAST(d.[orig_creditor] as varchar ), '<NULL>'),
     ISNULL(CAST(i.[orig_creditor] as varchar ), '<NULL>'),
     '[orig_creditor]', CURRENT_TIMESTAMP, suser_sname()
     FROM Inserted i
     LEFT OUTER JOIN Deleted d on i.file_no = d.file_no
     WHERE (  d.[orig_creditor] <> i.[orig_creditor]
      OR (d.[orig_creditor] IS NULL AND i.[orig_creditor] IS NOT NULL)
      OR (d.[orig_creditor] IS NOT NULL AND i.[orig_creditor] IS NULL)
      )
     IF UPDATE([orig_int_rate])
     INSERT INTO Changes
     (file_no, table_name, changed_from,
     changed_to,
     changed_column, created, createdby)
     SELECT i.file_no, 'DebtorInfo', ISNULL(CAST(d.[orig_int_rate] as varchar ), '<NULL>'),
     ISNULL(CAST(i.[orig_int_rate] as varchar ), '<NULL>'),
     '[orig_int_rate]', CURRENT_TIMESTAMP, suser_sname()
     FROM Inserted i
     LEFT OUTER JOIN Deleted d on i.file_no = d.file_no
     WHERE (  d.[orig_int_rate] <> i.[orig_int_rate]
      OR (d.[orig_int_rate] IS NULL AND i.[orig_int_rate] IS NOT NULL)
      OR (d.[orig_int_rate] IS NOT NULL AND i.[orig_int_rate] IS NULL)
      )
     IF UPDATE([orig_loan_amt])
     INSERT INTO Changes
     (file_no, table_name, changed_from,
     changed_to,
     changed_column, created, createdby)
     SELECT i.file_no, 'DebtorInfo', ISNULL(CAST(d.[orig_loan_amt] as varchar ), '<NULL>'),
     ISNULL(CAST(i.[orig_loan_amt] as varchar ), '<NULL>'),
     '[orig_loan_amt]', CURRENT_TIMESTAMP, suser_sname()
     FROM Inserted i
     LEFT OUTER JOIN Deleted d on i.file_no = d.file_no
     WHERE (  d.[orig_loan_amt] <> i.[orig_loan_amt]
      OR (d.[orig_loan_amt] IS NULL AND i.[orig_loan_amt] IS NOT NULL)
      OR (d.[orig_loan_amt] IS NOT NULL AND i.[orig_loan_amt] IS NULL)
      )
     IF UPDATE([owner_code])
     INSERT INTO Changes
     (file_no, table_name, changed_from,
     changed_to,
     changed_column, created, createdby)
     SELECT i.file_no, 'DebtorInfo', ISNULL(CAST(d.[owner_code] as varchar ), '<NULL>'),
     ISNULL(CAST(i.[owner_code] as varchar ), '<NULL>'),
     '[owner_code]', CURRENT_TIMESTAMP, suser_sname()
     FROM Inserted i
     LEFT OUTER JOIN Deleted d on i.file_no = d.file_no
     WHERE (  d.[owner_code] <> i.[owner_code]
      OR (d.[owner_code] IS NULL AND i.[owner_code] IS NOT NULL)
      OR (d.[owner_code] IS NOT NULL AND i.[owner_code] IS NULL)
      )
     IF UPDATE([owner_int_rate])
     INSERT INTO Changes
     (file_no, table_name, changed_from,
     changed_to,
     changed_column, created, createdby)
     SELECT i.file_no, 'DebtorInfo', ISNULL(CAST(d.[owner_int_rate] as varchar ), '<NULL>'),
     ISNULL(CAST(i.[owner_int_rate] as varchar ), '<NULL>'),
     '[owner_int_rate]', CURRENT_TIMESTAMP, suser_sname()
     FROM Inserted i
     LEFT OUTER JOIN Deleted d on i.file_no = d.file_no
     WHERE (  d.[owner_int_rate] <> i.[owner_int_rate]
      OR (d.[owner_int_rate] IS NULL AND i.[owner_int_rate] IS NOT NULL)
      OR (d.[owner_int_rate] IS NOT NULL AND i.[owner_int_rate] IS NULL)
      )
     IF UPDATE([owner_status])
     INSERT INTO Changes
     (file_no, table_name, changed_from,
     changed_to,
     changed_column, created, createdby)
     SELECT i.file_no, 'DebtorInfo', ISNULL(CAST(d.[owner_status] as varchar ), '<NULL>'),
     ISNULL(CAST(i.[owner_status] as varchar ), '<NULL>'),
     '[owner_status]', CURRENT_TIMESTAMP, suser_sname()
     FROM Inserted i
     LEFT OUTER JOIN Deleted d on i.file_no = d.file_no
     WHERE (  d.[owner_status] <> i.[owner_status]
      OR (d.[owner_status] IS NULL AND i.[owner_status] IS NOT NULL)
      OR (d.[owner_status] IS NOT NULL AND i.[owner_status] IS NULL)
      )
     IF UPDATE([past_int_balance])
     INSERT INTO Changes
     (file_no, table_name, changed_from,
     changed_to,
     changed_column, created, createdby)
     SELECT i.file_no, 'DebtorInfo', ISNULL(CAST(d.[past_int_balance] as varchar ), '<NULL>'),
     ISNULL(CAST(i.[past_int_balance] as varchar ), '<NULL>'),
     '[past_int_balance]', CURRENT_TIMESTAMP, suser_sname()
     FROM Inserted i
     LEFT OUTER JOIN Deleted d on i.file_no = d.file_no
     WHERE (  d.[past_int_balance] <> i.[past_int_balance]
      OR (d.[past_int_balance] IS NULL AND i.[past_int_balance] IS NOT NULL)
      OR (d.[past_int_balance] IS NOT NULL AND i.[past_int_balance] IS NULL)
      )
     IF UPDATE([placement_balance])
     INSERT INTO Changes
     (file_no, table_name, changed_from,
     changed_to,
     changed_column, created, createdby)
     SELECT i.file_no, 'DebtorInfo', ISNULL(CAST(d.[placement_balance] as varchar ), '<NULL>'),
     ISNULL(CAST(i.[placement_balance] as varchar ), '<NULL>'),
     '[placement_balance]', CURRENT_TIMESTAMP, suser_sname()
     FROM Inserted i
     LEFT OUTER JOIN Deleted d on i.file_no = d.file_no
     WHERE (  d.[placement_balance] <> i.[placement_balance]
      OR (d.[placement_balance] IS NULL AND i.[placement_balance] IS NOT NULL)
      OR (d.[placement_balance] IS NOT NULL AND i.[placement_balance] IS NULL)
      )
     IF UPDATE([prin_balance])
     INSERT INTO Changes
     (file_no, table_name, changed_from,
     changed_to,
     changed_column, created, createdby)
     SELECT i.file_no, 'DebtorInfo', ISNULL(CAST(d.[prin_balance] as varchar ), '<NULL>'),
     ISNULL(CAST(i.[prin_balance] as varchar ), '<NULL>'),
     '[prin_balance]', CURRENT_TIMESTAMP, suser_sname()
     FROM Inserted i
     LEFT OUTER JOIN Deleted d on i.file_no = d.file_no
     WHERE (  d.[prin_balance] <> i.[prin_balance]
      OR (d.[prin_balance] IS NULL AND i.[prin_balance] IS NOT NULL)
      OR (d.[prin_balance] IS NOT NULL AND i.[prin_balance] IS NULL)
      )
                                                                                                                                                                                                                                                                                                                                                   IF UPDATE([purchase_id])
     INSERT INTO Changes
     (file_no, table_name, changed_from,
     changed_to,
     changed_column, created, createdby)
     SELECT i.file_no, 'DebtorInfo', ISNULL(CAST(d.[purchase_id] as varchar ), '<NULL>'),
     ISNULL(CAST(i.[purchase_id] as varchar ), '<NULL>'),
     '[purchase_id]', CURRENT_TIMESTAMP, suser_sname()
     FROM Inserted i
     LEFT OUTER JOIN Deleted d on i.file_no = d.file_no
     WHERE (  d.[purchase_id] <> i.[purchase_id]
      OR (d.[purchase_id] IS NULL AND i.[purchase_id] IS NOT NULL)
      OR (d.[purchase_id] IS NOT NULL AND i.[purchase_id] IS NULL)
      )
     IF UPDATE([purchase_price])
     INSERT INTO Changes
     (file_no, table_name, changed_from,
     changed_to,
     changed_column, created, createdby)
     SELECT i.file_no, 'DebtorInfo', ISNULL(CAST(d.[purchase_price] as varchar ), '<NULL>'),
     ISNULL(CAST(i.[purchase_price] as varchar ), '<NULL>'),
     '[purchase_price]', CURRENT_TIMESTAMP, suser_sname()
     FROM Inserted i
     LEFT OUTER JOIN Deleted d on i.file_no = d.file_no
     WHERE (  d.[purchase_price] <> i.[purchase_price]
      OR (d.[purchase_price] IS NULL AND i.[purchase_price] IS NOT NULL)
      OR (d.[purchase_price] IS NOT NULL AND i.[purchase_price] IS NULL)
      )
     IF UPDATE([Quan_BK_Hit])
     INSERT INTO Changes
     (file_no, table_name, changed_from,
     changed_to,
     changed_column, created, createdby)
     SELECT i.file_no, 'DebtorInfo', ISNULL(CAST(d.[Quan_BK_Hit] as varchar ), '<NULL>'),
     ISNULL(CAST(i.[Quan_BK_Hit] as varchar ), '<NULL>'),
     '[Quan_BK_Hit]', CURRENT_TIMESTAMP, suser_sname()
     FROM Inserted i
     LEFT OUTER JOIN Deleted d on i.file_no = d.file_no
     WHERE (  d.[Quan_BK_Hit] <> i.[Quan_BK_Hit]
      OR (d.[Quan_BK_Hit] IS NULL AND i.[Quan_BK_Hit] IS NOT NULL)
      OR (d.[Quan_BK_Hit] IS NOT NULL AND i.[Quan_BK_Hit] IS NULL)
      )
     IF UPDATE([recall_process])
     INSERT INTO Changes
     (file_no, table_name, changed_from,
     changed_to,
     changed_column, created, createdby)
     SELECT i.file_no, 'DebtorInfo', ISNULL(CAST(d.[recall_process] as varchar ), '<NULL>'),
     ISNULL(CAST(i.[recall_process] as varchar ), '<NULL>'),
     '[recall_process]', CURRENT_TIMESTAMP, suser_sname()
     FROM Inserted i
     LEFT OUTER JOIN Deleted d on i.file_no = d.file_no
     WHERE (  d.[recall_process] <> i.[recall_process]
      OR (d.[recall_process] IS NULL AND i.[recall_process] IS NOT NULL)
      OR (d.[recall_process] IS NOT NULL AND i.[recall_process] IS NULL)
      )
     IF UPDATE([resale_permitted])
     INSERT INTO Changes
     (file_no, table_name, changed_from,
     changed_to,
     changed_column, created, createdby)
     SELECT i.file_no, 'DebtorInfo', ISNULL(CAST(d.[resale_permitted] as varchar ), '<NULL>'),
     ISNULL(CAST(i.[resale_permitted] as varchar ), '<NULL>'),
     '[resale_permitted]', CURRENT_TIMESTAMP, suser_sname()
     FROM Inserted i
     LEFT OUTER JOIN Deleted d on i.file_no = d.file_no
     WHERE (  d.[resale_permitted] <> i.[resale_permitted]
      OR (d.[resale_permitted] IS NULL AND i.[resale_permitted] IS NOT NULL)
      OR (d.[resale_permitted] IS NOT NULL AND i.[resale_permitted] IS NULL)
      )
     IF UPDATE([return_mail])
     INSERT INTO Changes
     (file_no, table_name, changed_from,
     changed_to,
     changed_column, created, createdby)
     SELECT i.file_no, 'DebtorInfo', ISNULL(CAST(d.[return_mail] as varchar ), '<NULL>'),
     ISNULL(CAST(i.[return_mail] as varchar ), '<NULL>'),
     '[return_mail]', CURRENT_TIMESTAMP, suser_sname()
     FROM Inserted i
     LEFT OUTER JOIN Deleted d on i.file_no = d.file_no
     WHERE (  d.[return_mail] <> i.[return_mail]
      OR (d.[return_mail] IS NULL AND i.[return_mail] IS NOT NULL)
      OR (d.[return_mail] IS NOT NULL AND i.[return_mail] IS NULL)
      )
     IF UPDATE([rz_acct_no])
     INSERT INTO Changes
     (file_no, table_name, changed_from,
     changed_to,
     changed_column, created, createdby)
     SELECT i.file_no, 'DebtorInfo', ISNULL(CAST(d.[rz_acct_no] as varchar ), '<NULL>'),
     ISNULL(CAST(i.[rz_acct_no] as varchar ), '<NULL>'),
     '[rz_acct_no]', CURRENT_TIMESTAMP, suser_sname()
     FROM Inserted i
     LEFT OUTER JOIN Deleted d on i.file_no = d.file_no
     WHERE (  d.[rz_acct_no] <> i.[rz_acct_no]
      OR (d.[rz_acct_no] IS NULL AND i.[rz_acct_no] IS NOT NULL)
      OR (d.[rz_acct_no] IS NOT NULL AND i.[rz_acct_no] IS NULL)
      )
     IF UPDATE([section_no])
     INSERT INTO Changes
     (file_no, table_name, changed_from,
     changed_to,
     changed_column, created, createdby)
     SELECT i.file_no, 'DebtorInfo', ISNULL(CAST(d.[section_no] as varchar ), '<NULL>'),
     ISNULL(CAST(i.[section_no] as varchar ), '<NULL>'),
     '[section_no]', CURRENT_TIMESTAMP, suser_sname()
     FROM Inserted i
     LEFT OUTER JOIN Deleted d on i.file_no = d.file_no
     WHERE (  d.[section_no] <> i.[section_no]
      OR (d.[section_no] IS NULL AND i.[section_no] IS NOT NULL)
      OR (d.[section_no] IS NOT NULL AND i.[section_no] IS NULL)
      )
     IF UPDATE([ssn_no])
     INSERT INTO Changes
     (file_no, table_name, changed_from,
     changed_to,
     changed_column, created, createdby)
     SELECT i.file_no, 'DebtorInfo', ISNULL(CAST(d.[ssn_no] as varchar ), '<NULL>'),
     ISNULL(CAST(i.[ssn_no] as varchar ), '<NULL>'),
     '[ssn_no]', CURRENT_TIMESTAMP, suser_sname()
     FROM Inserted i
     LEFT OUTER JOIN Deleted d on i.file_no = d.file_no
     WHERE (  d.[ssn_no] <> i.[ssn_no]
      OR (d.[ssn_no] IS NULL AND i.[ssn_no] IS NOT NULL)
      OR (d.[ssn_no] IS NOT NULL AND i.[ssn_no] IS NULL)
      )
     IF UPDATE([state])
     INSERT INTO Changes
     (file_no, table_name, changed_from,
     changed_to,
     changed_column, created, createdby)
     SELECT i.file_no, 'DebtorInfo', ISNULL(CAST(d.[state] as varchar ), '<NULL>'),
     ISNULL(CAST(i.[state] as varchar ), '<NULL>'),
     '[state]', CURRENT_TIMESTAMP, suser_sname()
     FROM Inserted i
     LEFT OUTER JOIN Deleted d on i.file_no = d.file_no
     WHERE (  d.[state] <> i.[state]
      OR (d.[state] IS NULL AND i.[state] IS NOT NULL)
      OR (d.[state] IS NOT NULL AND i.[state] IS NULL)
      )
     IF UPDATE([statute_type])
     INSERT INTO Changes
     (file_no, table_name, changed_from,
     changed_to,
     changed_column, created, createdby)
     SELECT i.file_no, 'DebtorInfo', ISNULL(CAST(d.[statute_type] as varchar ), '<NULL>'),
     ISNULL(CAST(i.[statute_type] as varchar ), '<NULL>'),
     '[statute_type]', CURRENT_TIMESTAMP, suser_sname()
     FROM Inserted i
     LEFT OUTER JOIN Deleted d on i.file_no = d.file_no
     WHERE (  d.[statute_type] <> i.[statute_type]
      OR (d.[statute_type] IS NULL AND i.[statute_type] IS NOT NULL)
      OR (d.[statute_type] IS NOT NULL AND i.[statute_type] IS NULL)
      )
                                                                                                                                                                                                                                                                                                                                                   IF UPDATE([Sub_Entity_ID])
     INSERT INTO Changes
     (file_no, table_name, changed_from,
     changed_to,
     changed_column, created, createdby)
     SELECT i.file_no, 'DebtorInfo', ISNULL(CAST(d.[Sub_Entity_ID] as varchar ), '<NULL>'),
     ISNULL(CAST(i.[Sub_Entity_ID] as varchar ), '<NULL>'),
     '[Sub_Entity_ID]', CURRENT_TIMESTAMP, suser_sname()
     FROM Inserted i
     LEFT OUTER JOIN Deleted d on i.file_no = d.file_no
     WHERE (  d.[Sub_Entity_ID] <> i.[Sub_Entity_ID]
      OR (d.[Sub_Entity_ID] IS NULL AND i.[Sub_Entity_ID] IS NOT NULL)
      OR (d.[Sub_Entity_ID] IS NOT NULL AND i.[Sub_Entity_ID] IS NULL)
      )
     IF UPDATE([total_paycode_six])
     INSERT INTO Changes
     (file_no, table_name, changed_from,
     changed_to,
     changed_column, created, createdby)
     SELECT i.file_no, 'DebtorInfo', ISNULL(CAST(d.[total_paycode_six] as varchar ), '<NULL>'),
     ISNULL(CAST(i.[total_paycode_six] as varchar ), '<NULL>'),
     '[total_paycode_six]', CURRENT_TIMESTAMP, suser_sname()
     FROM Inserted i
     LEFT OUTER JOIN Deleted d on i.file_no = d.file_no
     WHERE (  d.[total_paycode_six] <> i.[total_paycode_six]
      OR (d.[total_paycode_six] IS NULL AND i.[total_paycode_six] IS NOT NULL)
      OR (d.[total_paycode_six] IS NOT NULL AND i.[total_paycode_six] IS NULL)
      )
     IF UPDATE([total_payment_count])
     INSERT INTO Changes
     (file_no, table_name, changed_from,
     changed_to,
     changed_column, created, createdby)
     SELECT i.file_no, 'DebtorInfo', ISNULL(CAST(d.[total_payment_count] as varchar ), '<NULL>'),
     ISNULL(CAST(i.[total_payment_count] as varchar ), '<NULL>'),
     '[total_payment_count]', CURRENT_TIMESTAMP, suser_sname()
     FROM Inserted i
     LEFT OUTER JOIN Deleted d on i.file_no = d.file_no
     WHERE (  d.[total_payment_count] <> i.[total_payment_count]
      OR (d.[total_payment_count] IS NULL AND i.[total_payment_count] IS NOT NULL)
      OR (d.[total_payment_count] IS NOT NULL AND i.[total_payment_count] IS NULL)
      )
     IF UPDATE([total_payments])
     INSERT INTO Changes
     (file_no, table_name, changed_from,
     changed_to,
     changed_column, created, createdby)
     SELECT i.file_no, 'DebtorInfo', ISNULL(CAST(d.[total_payments] as varchar ), '<NULL>'),
     ISNULL(CAST(i.[total_payments] as varchar ), '<NULL>'),
     '[total_payments]', CURRENT_TIMESTAMP, suser_sname()
     FROM Inserted i
     LEFT OUTER JOIN Deleted d on i.file_no = d.file_no
     WHERE (  d.[total_payments] <> i.[total_payments]
      OR (d.[total_payments] IS NULL AND i.[total_payments] IS NOT NULL)
      OR (d.[total_payments] IS NOT NULL AND i.[total_payments] IS NULL)
      )
     IF UPDATE([tranche_id])
     INSERT INTO Changes
     (file_no, table_name, changed_from,
     changed_to,
     changed_column, created, createdby)
     SELECT i.file_no, 'DebtorInfo', ISNULL(CAST(d.[tranche_id] as varchar ), '<NULL>'),
     ISNULL(CAST(i.[tranche_id] as varchar ), '<NULL>'),
     '[tranche_id]', CURRENT_TIMESTAMP, suser_sname()
     FROM Inserted i
     LEFT OUTER JOIN Deleted d on i.file_no = d.file_no
     WHERE (  d.[tranche_id] <> i.[tranche_id]
      OR (d.[tranche_id] IS NULL AND i.[tranche_id] IS NOT NULL)
      OR (d.[tranche_id] IS NOT NULL AND i.[tranche_id] IS NULL)
      )
     IF UPDATE([working_balance])
     INSERT INTO Changes
     (file_no, table_name, changed_from,
     changed_to,
     changed_column, created, createdby)
     SELECT i.file_no, 'DebtorInfo', ISNULL(CAST(d.[working_balance] as varchar ), '<NULL>'),
     ISNULL(CAST(i.[working_balance] as varchar ), '<NULL>'),
     '[working_balance]', CURRENT_TIMESTAMP, suser_sname()
     FROM Inserted i
     LEFT OUTER JOIN Deleted d on i.file_no = d.file_no
     WHERE (  d.[working_balance] <> i.[working_balance]
      OR (d.[working_balance] IS NULL AND i.[working_balance] IS NOT NULL)
      OR (d.[working_balance] IS NOT NULL AND i.[working_balance] IS NULL)
      )
     IF UPDATE([zip])
     INSERT INTO Changes
     (file_no, table_name, changed_from,
     changed_to,
     changed_column, created, createdby)
     SELECT i.file_no, 'DebtorInfo', ISNULL(CAST(d.[zip] as varchar ), '<NULL>'),
     ISNULL(CAST(i.[zip] as varchar ), '<NULL>'),
     '[zip]', CURRENT_TIMESTAMP, suser_sname()
     FROM Inserted i
     LEFT OUTER JOIN Deleted d on i.file_no = d.file_no
     WHERE (  d.[zip] <> i.[zip]
      OR (d.[zip] IS NULL AND i.[zip] IS NOT NULL)
      OR (d.[zip] IS NOT NULL AND i.[zip] IS NULL)
      )
     
     

    Thank you
  • Does the form just update one row or does it change multiple rows? i.e. how many rows are in the inserted table?

  • Well, a user can update any number of fields on the form, and there about 30or so fields.
    However, I can tell you that I personally just updated on the field and it would add other data. Sometimes just on the one field and other times two or three.
    And again, I can do this a number of time like I am doing now and nothing, it works great, and then it will add fields.
     I think it is data stuck in cash, which is why I was asking the second quest in my post.

  • Does file_no have a unique constraint on it in table dbo.DebtorInfo?

  • No it does not

  • itmasterw 60042 - Friday, December 7, 2018 7:57 AM

    No it does not

    I think you should be joining inserted to deleted on a unique key for the row.

  • I think you'll need to actually compare the inserted and deleted data in the trigger if you want to capture actual changes.  the UPDATE() function in a trigger seems to capture whether the field was included in the update statement regardless of whether the data actually changed.

  • Yah that is why I was asking the 2nd part of the question, I do not know how to do that. And everything that I tried so for has not worked.

  • itmasterw 60042 - Friday, December 7, 2018 8:22 AM

    Yah that is why I was asking the 2nd part of the question, I do not know how to do that. And everything that I tried so for has not worked.

    Ah... .can they change the file_no in the form?  If so that will break the logic you're using in the joins on matching inserted to deleted.

    what is the actual update statement from the form?

Viewing 11 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic. Login to reply