Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trigger Help Please

Status
Not open for further replies.

shiggyshag

Programmer
Dec 14, 2001
227
0
0
GB
Hi

I have a table where all the columns are updated even if there is no change to some of the columns from an SP

Now I have the following trigger but because I update all the columns it runs can I check the values are different then run it if they are?

ALTER TRIGGER TriggerContacts
ON dbo.tContacts
FOR update AS

IF Update(Forename)
BEGIN
INSERT INTO tContactHistory (ContactID, UpdateDate, ColumnName, oldvalue, newvalue, UserID)
SELECT del.ContactID, GetDate(), 'Forename', del.Forename, ins.Forename, del.LastHistoryUserID
FROM deleted del inner join inserted ins on del.ContactID = ins.ContactID
end

IF Update(Surname)
BEGIN
INSERT INTO tContactHistory (ContactID, UpdateDate, ColumnName, oldvalue, newvalue, UserID)
SELECT del.ContactID, GetDate(), 'Surname', del.Surname, ins.Surname, del.LastHistoryUserID
FROM deleted del inner join inserted ins on del.ContactID = ins.ContactID
end


Cheers
 
Its ok worked it out

where del.Forename <> ins.Forename
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top