I want to always update the value of an update row in the database.
Imagine, i have a table with names and prices Every time a row is inserted or updated, i want to lower the price by a fixed amount.
How can I do this with SQL server 2005?
I have now something like
CREATE TRIGGER LowerPriceOnInsert ON products
AFTER INSERT, UPDATE
AS
IF UPDATE(ProductPrice)
Ok, so let's say you wanted to reduce the price by 5 cents:
UPDATE p
SET price = price - 0.05
FROM dbo.Products AS p
INNER JOIN inserted AS i
ON p.ProductID = i.ProductID;
http://msdn.microsoft.com/en-us/library/ms191300.aspx
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With