Posting another trigger question - using SQL2005
I have the following trigger that works fine if there is only one row for the trigger to insert:
ALTER TRIGGER [updCommReceived_OtherPricePlans]
ON [dbo].[TransactionEntry]
FOR INSERT
AS
INSERT INTO c_CommReceived(StoreID, TransactionNumber, TransID, Commission, QtyBonus, Coop)
SELECT INSERTED.StoreID, INSERTED.TransactionNumber, INSERTED.ID,
(SELECT c_CommRates.Commission FROM c_CommRates WHERE c_CommRates.DepartmentID = (SELECT DepartmentID FROM Item WHERE Item.ID = INSERTED.ItemID)
AND (SELECT EquivalentValue FROM c_CellPlans WHERE c_CellPlans.ItemID = INSERTED.ItemID) >= LowerBound
AND (SELECT EquivalentValue FROM c_CellPlans WHERE c_CellPlans.ItemID = INSERTED.ItemID) <= Upperbound
) * INSERTED.Quantity,
5 * INSERTED.Quantity, 0 * INSERTED.Quantity
FROM INSERTED
INNER JOIN Item ON INSERTED.ItemID = Item.ID
WHERE Item.DepartmentID IN (65, 67)
However if there are more than one records in the INSERTED table, requiring more than one record to be inserted into the c_commreceived table, the trigger fails. Any idea as to why this is not working?
Thank you,
Kevin
I have the following trigger that works fine if there is only one row for the trigger to insert:
ALTER TRIGGER [updCommReceived_OtherPricePlans]
ON [dbo].[TransactionEntry]
FOR INSERT
AS
INSERT INTO c_CommReceived(StoreID, TransactionNumber, TransID, Commission, QtyBonus, Coop)
SELECT INSERTED.StoreID, INSERTED.TransactionNumber, INSERTED.ID,
(SELECT c_CommRates.Commission FROM c_CommRates WHERE c_CommRates.DepartmentID = (SELECT DepartmentID FROM Item WHERE Item.ID = INSERTED.ItemID)
AND (SELECT EquivalentValue FROM c_CellPlans WHERE c_CellPlans.ItemID = INSERTED.ItemID) >= LowerBound
AND (SELECT EquivalentValue FROM c_CellPlans WHERE c_CellPlans.ItemID = INSERTED.ItemID) <= Upperbound
) * INSERTED.Quantity,
5 * INSERTED.Quantity, 0 * INSERTED.Quantity
FROM INSERTED
INNER JOIN Item ON INSERTED.ItemID = Item.ID
WHERE Item.DepartmentID IN (65, 67)
However if there are more than one records in the INSERTED table, requiring more than one record to be inserted into the c_commreceived table, the trigger fails. Any idea as to why this is not working?
Thank you,
Kevin