Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


when one column is updated, want to update another column in same table using trigger.


when one column is updated, want to update another column in same table using trigger.

Author
Message
Joy Smith San
Joy Smith San
SSCrazy
SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)

Group: General Forum Members
Points: 2852 Visits: 3200
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.
SwePeso
SwePeso
Hall of Fame
Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)Hall of Fame (3.5K reputation)

Group: General Forum Members
Points: 3455 Visits: 3432
Something similar to this?

CREATE TRIGGER dbo.trgMyTotalUpdate ON dbo.MyTable
AFTER UPDATE
AS

IF UPDATE(Quantity)
UPDATE mt
SET mt.Total = i.Quantity * i.Price
FROM dbo.MyTable AS mt
INNER JOIN inserted AS i ON i.PkCol = mt.PkCol




N 56°04'39.16"
E 12°55'05.25"
Joy Smith San
Joy Smith San
SSCrazy
SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)SSCrazy (2.9K reputation)

Group: General Forum Members
Points: 2852 Visits: 3200
Thanks a lot...It's working...
Jerry Hung
Jerry Hung
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1186 Visits: 1208
how about a Computed Column that "computes" i.Quantity * i.Price

http://www.sqlservercentral.com/articles/User-Defined+functions/complexcomputedcolumns/2397/

SQLServerNewbie

MCITP: Database Administrator SQL Server 2005
panistefanin
panistefanin
SSC Journeyman
SSC Journeyman (86 reputation)SSC Journeyman (86 reputation)SSC Journeyman (86 reputation)SSC Journeyman (86 reputation)SSC Journeyman (86 reputation)SSC Journeyman (86 reputation)SSC Journeyman (86 reputation)SSC Journeyman (86 reputation)

Group: General Forum Members
Points: 86 Visits: 3
Hello! I really liked your story. Thank you!
You are great!:-)
sprint.com chat
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search