Sql Trigger wont run the Complete update statement?

t3st12345

New Member
Problem: I wrote a trigger that is supposed to update the \[code\]INVOICE\[/code\] table after an \[code\]INSERT\[/code\] into the \[code\]LINE\[/code\] table but it won't update the invoice table. The trigger fires but the \[code\]Update\[/code\] statement block won't execute. I debugged while I executed the \[code\]INSERT\[/code\] into the line table and found out as soon as the it gets to the \[code\]UPDATE\[/code\] statement it jumps over it and doesn't run that code. I have been trying to figure this out for a couple of days now.Here is my trigger code\[code\]ALTER TRIGGER [dbo].[trgInvoiceInsert] ON [dbo].[LINE]AFTER INSERTAS declare @linUnits numeric(9,2); declare @linPrice numeric(9,2); declare @invNum int; select @linUnits = LINE_UNITS from inserted; select @linPrice = LINE_PRICE from inserted; select @invNum = INV_NUMBER from inserted;BEGIN UPDATE i --From here it jumps to the start of the next Update SET INV_SUBTOTAL = INV_SUBTOTAL + (@linUnits * @linPrice) FROM dbo.INVOICE as i WHERE i.INV_NUMBER = @invNum UPDATE i SET INV_TOTAL = INV_SUBTOTAL + INV_TAX FROM dbo.INVOICE as i WHERE i.INV_NUMBER = @invNum PRINT 'Trigger fired Successfully.'\[/code\]END
 
Top