Hello, I'm trying to get a trigger to work and I'm having a bit of trouble. I have a journal system, and when a user adds a new entry, I need to either upadate a record in another table or insert a record. Here's what I got so farCREATE TRIGGER JournalEntriesAdd ON [JOURNAL_ENTRIES] FOR INSERTASBEGIN Set NoCount On declare @MemberID int, @EntryDate char(14) select @MemberID = MEMBER_ID, @EntryDate = ENTRY_DATE from JOURNAL_ENTRIES where ENTRY_ID = @@identity declare @NeedInsert int --find out if this user has a JOURNAL_USERS record created already select @NeedInsert = MEMBER_ID from JOURNAL_USERS where MEMBER_ID = @MemberID if @NeedInsert = @MemberID begin update JOURNAL_USERS set LAST_ENTRY = @EntryDate where MEMBER_ID = @MemberID end if @NeedInsert <> @MemberID begin insert into JOURNAL_USERS (MEMBER_ID, LAST_ENTRY) values (@MemberID, @EntryDate ) endend
what I'm trying to do is update the LAST_ENTRY field in the users table with the date of their last entry. If this is the first entry they've made, a JOURNAL_USERS record won't exist and one needs to be inserted. Existing records will get updated just fine, but I can't get it to insert a new record....any help would be greatly appreciatedThanks-- AdamThe Internet ClubHouseCome join the communityEdited by - Anacrusis on 12/20/2002 09:50:28