Viewing 4 posts - 1 through 5 (of 5 total)
CREATE TRIGGER myInsertTrigger
ON OrderItems
AFTER UPDATE
AS
DECLARE @Count INT;
SELECT @Count = (SELECT ItemCount from UPDATED)
BEGIN
IF(@Count>[OLD].ItemCount)
THEN
UPDATE Inventory
SET InventoryCount = InventoryCount - @Count
WHERE Inventory.ItemId IN(SELECT ItemId FROM UPDATED)
ELSEIF (@Count<[OLD].ItemCount)
THEN
UPDATE Inventory
SET InventoryCount = InventoryCount +...
April 4, 2011 at 3:34 am
what to do if more than one row is deleted ?
April 4, 2011 at 2:44 am
CREATE TRIGGER myTrigger
ON OrderItems
AFTER DELETE
AS
DECLARE @Count INT;
SELECT @Count = (SELECT ItemCount from Deleted)
BEGIN
UPDATE Inventory
SET InventoryCount = InventoryCount + @Count
WHERE Inventory.ItemId IN(SELECT ItemId FROM Deleted)
END
The correct one.
April 4, 2011 at 1:49 am
Viewing 4 posts - 1 through 5 (of 5 total)