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.
Author |
Topic |
icw
Constraint Violating Yak Guru
378 Posts |
Posted - 2010-06-29 : 16:39:13
|
HiCan anyone point out what's wrong with my trigger.It seemed to install OK but doens't seem to do what i want it to.What i want is that everytime I insert a new entry in the "Journal" table it copies the value from a field in the journal called "Entrytext2" in to a field called "LatestJournal" in a table called "Calllog" (there is a 1:m relationship between calllog and journal)my trigger is below.-- Create date: <20/09/09>-- Description: <Trigger to Copy the latest Journal into the "LatestJournal" field in calllog Table>-- =============================================CREATE TRIGGER [dbo].[NewJournalCopy] ON Nuneaton.dbo.[Journal]FOR INSERTASDeclare @CalliD Varchar(8) Declare @NewJournalStr Varchar (8000)--Select the Callid ofthe entry just inserted into Journal Select @callid=CallidFROM INserted IF @Callid IS NOT NULLBegin--Update CallLog with the text UPDATE Nuneaton.dbo.[Calllog]SET LatestJournal = @NewJournalStrWhere CallID = @CallIDEND |
|
icw
Constraint Violating Yak Guru
378 Posts |
Posted - 2010-06-29 : 16:48:00
|
I noticed i didn't populate one of my parameters. So I've doen that now but it still doesn't work.see below for new codeAlter TRIGGER [dbo].[NewJournalCopy] ON Nuneaton.dbo.[Journal]FOR INSERTASDeclare @CalliD Varchar(8) Declare @NewJournalStr Varchar (8000)--Select the Callid ofthe entry just inserted into Journal Select @callid=CallidFROM INserted SELECT @NewJournalStr = Entrytext2FROM Nuneaton.dbo.[Journal]WHERE CallID = @CallIDIF @Callid IS NOT NULLBegin--Update CallLog with the text UPDATE Nuneaton.dbo.[Calllog]SET LatestJournal = @NewJournalStrWhere CallID = @CallIDEND |
 |
|
icw
Constraint Violating Yak Guru
378 Posts |
Posted - 2010-06-29 : 16:49:59
|
Actually it is working, i just needed to refresh my screen |
 |
|
X002548
Not Just a Number
15586 Posts |
Posted - 2010-06-29 : 16:55:20
|
[code]/*What i want is that everytime I insert a new entry in the "Journal" table Copy the value from a field in the journal called "Entrytext2" in to a field called "LatestJournal" in a table called "Calllog" */CREATE TRIGGER [dbo].[NewJournalCopy] ON Nuneaton.dbo.[Journal] FOR INSERTASINSERT INTO Calllog(LatestJournal)SELECT Entrytext2 FROM insertedGO[/code]Brett8-)Hint: Want your questions answered fast? Follow the direction in this linkhttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxAdd yourself!http://www.frappr.com/sqlteam |
 |
|
|
|
|