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/[/url]
November 29, 2016 at 4:32 am
This was removed by the editor as SPAM
April 23, 2017 at 6:39 am
This was removed by the editor as SPAM
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply