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
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
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.
BeanSmart website is not affiliated with any of the manufacturers or service providers discussed here.
All logos and trade names are the property of their respective owners.