当我想从一个表到另一个表获取其值时,但是当我想要编辑值时,它会将新值添加到tbl_ItemDetails。我只需要更新现有的行。
CREATE TRIGGER trigger_UpdateItemDetails ON tbl_PurchaseDetails
FOR INSERT AS
DECLARE @PurchaseID VARCHAR(20)
DECLARE @Quantity INT
DECLARE @WarehouseID VARCHAR(20)
SELECT @PurchaseID=(PurchaseID) FROM INSERTED
SELECT @Quantity=(ItemQuantity) FROM INSERTED
SELECT @WarehouseID=(WarehouseID) FROM INSERTED
INSERT INTO
tbl_ItemDetails
(PurchaseID,Quantity,WarehouseID)
VALUES
(@PurchaseID,@Quantity,@WarehouseID)
答案 0 :(得分:0)
让我从这开始: 你永远不应该编写无法处理集合的触发器。
CREATE TRIGGER trigger_UpdateItemDetails ON tbl_PurchaseDetails
FOR INSERT AS
UPDATE itm
SET PurchaseID=i.PurchaseID
,Quantity=i.ItemQuantity
,WarehouseID=i.WarehouseID
FROM INSERTED i
INNER JOIN tbl_ItemDetails itm ON i.???=itm.???
--I have no idea what your join clause should be as I don't know your data structure