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
 Transact-SQL (2005)
 Trigger Error

Author  Topic 

Meltdown
Starting Member

37 Posts

Posted - 2008-01-21 : 20:20:38
Hi all,

I'm trying to create an audit trigger and I have the following code:

Create Trigger dbo.tu_paymentaudit
ON dbo.Payments
FOR UPDATE
AS

Declare @now DATETIME
Set @now = getdate()

BEGIN TRY

Insert INTO dbo.tblPaymentAudit
(RowImage,Charges,ChangeDate,ChangeUser)
SELECT 'BEFORE',INSERTED.Charges,@now, suser_sname()
FROM DELETED

Insert INTO dbo.tblPaymentAudit
(RowImage,Charges,ChangeDate,ChangeUser)
SELECT 'AFTER',INSERTED.Charges,@now, suser_sname()
FROM INSERTED

END TRY

BEGIN CATCH
ROLLBACK TRANSACTION
END CATCH


But when I try to create/execute it, it keeps coming back with the following error:

Msg 4104, Level 16, State 1, Procedure tu_paymentaudit, Line 10
The multi-part identifier "INSERTED.Charges" could not be bound.

Can anyone tell me what's wrong please?

Thanks

rmiao
Master Smack Fu Yak Hacker

7266 Posts

Posted - 2008-01-21 : 20:26:15
Don't need INSERTED in this case.
Go to Top of Page

Meltdown
Starting Member

37 Posts

Posted - 2008-01-21 : 21:26:30
rmiao, thanks for the answer, I got that code from a book, so I couldn't understand how it could be wrong.

Regards
Melt
Go to Top of Page
   

- Advertisement -