Does anyone know how to right a trigger that will update Price level discounts? I.E. set Price1A to 1% less than the actual item.price.
This is what I have but it does not work as of yet, I am missing something in the code:
CREATE TRIGGER pricechange ON Item FOR UPDATE AS if update (item) begin set dbo.QuantityDiscount.Price1A =((item.Price)-(item.Price * 0.01)) from quantitydiscount, item where QuantityDiscount.Description = Item.ItemLookupCode end
Didn't find your answer? Ask the community — no account required.
A
Antonio Mazzeo
UPDATE Item SET PriceA = inserted.Price - (inserted.Price * 0.01) FROM inserted WHERE Item.ID = inserted.ID
:)
Please use primary key for compare two records..
bye antonio
R
Rob
Rob F.
There are two triggers one that update on the Price field updating and the other on an item being created(Insert).
CREATE TRIGGER [utr_Item_Price_PriceA_Insert] ON [Item] FOR INSERT AS
/*********************************************************** utr_Item_Price_PriceA_Insert sets Price A to PriceA to 1% less than the actual item.price.
************************************************************/ BEGIN UPDATE PriceA = =(Item.Price) -(Item.Price * 0.01) FROM Item INNER JOIN INSERTED i on Item.ItemLookupCode = i.ItemLookupcode
CREATE TRIGGER [utr_Item_Price_PriceA_Update] ON [Item] FOR UPDATE AS
/*********************************************************** utr_Item_Cost_PriceA_Insert sets Price A to PriceA to 1% less than the actual item.price.
************************************************************/ BEGIN IF UPDATE(Price) UPDATE PriceA = =(Item.Price) -(Item.Price * 0.01) FROM Item INNER JOIN INSERTED i on Item.ItemLookupCode = i.ItemLookupcode
END
This is to delete a trigger. IF EXISTS (SELECT name FROM sysobjects WHERE name 'insert_name_of_trigger_here_with_quotes' AND type = 'TR') DROP TRIGGER insert_name_of_trigger_here_no_quotes
Rob
R
Rob F.
We came up with this that works, generic percentages of course:
CREATE trigger pricechange on item for update as if update (price) begin
from quantitydiscount, item where quantitydiscount.id=item.quantitydiscountid
end
We are going to use SubDescription1 to determine which categories or items get set to which percentages, we just need to figure out the if then statement in the trigger.