September 24, 2008 at 11:18 pm
Dear All,
I have a table in which there are fields like Quantity, Price, Total etc.There's is also a primary key field in this table.
We have an interface where user can change the quantity (only quantity).
I want to write a trigger on this table which calculates Total (qty * price) whenever qantity is updated.
How can I do it..?. How will I know for which row the quantity is updated..?
Pleas help...
Thanks in advance..
Santhosh Nair.
September 25, 2008 at 12:41 am
Something similar to this?
CREATE TRIGGER dbo.trgMyTotalUpdate ON dbo.MyTable
AFTER UPDATE
AS
IF UPDATE(Quantity)
UPDATEmt
SETmt.Total = i.Quantity * i.Price
FROMdbo.MyTable AS mt
INNER JOINinserted AS i ON i.PkCol = mt.PkCol
N 56°04'39.16"
E 12°55'05.25"
September 25, 2008 at 1:24 am
Thanks a lot...It's working...
September 25, 2008 at 10:31 am
how about a Computed Column that "computes" i.Quantity * i.Price
http://www.sqlservercentral.com/articles/User-Defined+functions/complexcomputedcolumns/2397/%5B/url%5D
Viewing 4 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy