Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Other SQL Server Topics (2005)
 SQL 2005 Trigger Help

Author  Topic 

DMonnik
Starting Member

2 Posts

Posted - 2008-05-03 : 20:45:19
Hey Everyone,

Wasn't sure where to post this exactly but anyway here goes:

I have 2 tables called tblMember and tblMember History.
Everytime a row in tblMember gets updated the old row (before being updated) is put into tblMemberHistory.

In tblMember there is a field called [isChanged] which is set to "yes" on insert or update so i can gather which rows have been changed since my last visit to the db. When i gather all these rows that have changed since my last visit i set the [isChanged] field to "no".

My problem is now that when i go through the database and change the value in field [isChanged] to "No" it adds yes another copy of the row into the tblMemberHistory table which i would like to avoid.

Is there a method of coding a trigger to do what i currently have it doing but not add another row to the history table when i change [isChanged] to "No"

Thanks


BELOW IS MY CURRENT TRIGGER CODE:
=================================

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go

ALTER TRIGGER [MemberUpdated]
ON [dbo].[tblMember]
AFTER UPDATE
AS
BEGIN

SET NOCOUNT ON;

INSERT INTO tblMemberHistory
SELECT *
FROM Deleted

END
   

- Advertisement -