问题:我写了一个触发器,它应该在进入INVOICE
表之后更新表,但它不会更新发票表。触发器触发,但语句块不会执行。INSERT
LINE
Update
我在执行INSERT
到行表时进行了调试,发现一旦到达UPDATE
语句,它就会跳过它并且不运行该代码。几天来,我一直试图弄清楚这一点。
这是我的触发代码
ALTER TRIGGER [dbo].[trgInvoiceInsert] ON [dbo].[LINE]
AFTER INSERT
AS
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.'
结尾