2013-07-14 54 views
1

另一個表我是新來觸發 我有名字ArefSms而tblSalesProd觸發更新條件

後,我想插入我的觸發更新ArefSms其中tblSalesProd.SalesID = ArefSms.SalesID 爲此提出兩個表我下面寫的代碼

USE [ACEDB] 
GO 

SET ANSI_NULLS ON 
GO 
SET QUOTED_IDENTIFIER ON 
GO 

ALTER TRIGGER [dbo].[areftblSalesProd] ON [dbo].[tblSalesProd] 
AFTER INSERT 
AS 
Begin Try 
Update ArefSms 
     set 
     qt=inserted.ProdQty 
     where ArefSms.SalesID=inserted.SalesID 



End Try 
Begin Catch 

End catch 

,但現在我有錯誤

Msg 4104, Level 16, State 1, Procedure areftblSalesProd, Line 9 
The multi-part identifier "inserted.SalesID" could not be bound. 

我能做些什麼?

回答

3

您需要在update聲明中指定inserted。它是一個表參考:

Update ArefSms 
    set qt=inserted.ProdQty 
    from inserted 
    where ArefSms.SalesID=inserted.SalesID; 
+0

感謝這是我的答案 –

1

當更新從其它表的表(在本例inserted),我更喜歡使用JOINs語法:

UPDATE Aref 
SET Aref.qt=inserted.ProdQty 
FROM ArefSms Aref 
    INNER JOIN inserted ON Aref.SalesID=inserted.SalesID