Link to home
Start Free TrialLog in
Avatar of IT Guy
IT Guy

asked on

Identifying A Record from an On Update Trigger

I’ve created a trigger that checks to see whether a field has been updated by querying the status of the field ordinal Number with something like (03) & > 0 where 03 is my field ordinal.

I need to also read the updated record into a set of variables.

It is essential that I read the correct record as the field that is updated might not be unique.

How can I achieve this?
Avatar of Vitor Montalvão
Vitor Montalvão
Flag of Switzerland image

In a trigger you have access to the delete and insert tables where on the first one you have all the rows that has been delete and on the latter you have all the new rows. In an UPDATE operation you'll find rows in both tables.
You can also use the UPDATE() function in a trigger to check if a column has been changed or not.
So you'll need something like:
CREATE TRIGGER myUpdTrigger
ON TableName
AFTER UPDATE   
AS   
IF UPDATE (ColumnName) 
    BEGIN  
        -- Do here what you need to do if the column has been updated
    END;  
GO  

Open in new window

Avatar of IT Guy
IT Guy

ASKER

What I need to do it to be able to select the values of the entire record based upon one record having been updated.

I have my on update trigger, I have the ordinal of the column that has been updated - I just need a line and f code that will allow me to select the values from all fields that have been updated.

Do I select from deleted?
ASKER CERTIFIED SOLUTION
Avatar of Vitor Montalvão
Vitor Montalvão
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of IT Guy

ASKER

I'll try it and let you know. Thank you.
Avatar of IT Guy

ASKER

Worked - thank you