Better way to Update only those values changed?

  • The problem with IF UPDATE is that it cannot determine if the value actually changed only that the value was explicitly set.

    True...an additional check is needed

    If Update(Col1)

    BEGIN

     Insert  Audit (ColID, Value)

     Select  1, ---ID of Col1

       Col1

     From inserted i

     JOIN deleted d on i.PKID = d.PKID--Primary Key ID

     Where isnull(i.Col1, '') <> isnull(d.Col1, '')

    END

    Signature is NULL

  • Just doing the audit will suffice thou I do believe. Because you condition should be ON UPDATE for the table. Then you can compare changes over a period of time or just from the previous time. Doing the additional check is really not needed from an Audit standpoint.

  • Just doing the audit will suffice thou I do believe. Because you condition should be ON UPDATE for the table. Then you can compare changes over a period of time or just from the previous time. Doing the additional check is really not needed from an Audit standpoint.

    For many types of auditting that would be true.  For the specific instance I'm basing my responses on it is extremely important that all changes are captured only once.  If that's not an issue then this entire thread probably doesn't apply.

    cl

    Signature is NULL

  • Darn timeout got me again when I typing a long relavent statement.

    Two questions still need to be answered with this and can be handled thru auditing.

    1) What is the state of the data shoudl a further change occurr?

    2) When is the data no longer considered as changed?

    If the answer is for the last batch of updates then once viewed you can remove the entried from the audit table. If it is considered permanently changed but further changes can take place then you need a full audit trail. The real question is when is it no longer changed with regards to the persons perception.

Viewing 4 posts - 16 through 18 (of 18 total)

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