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

  • 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.

  • 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"

  • Thanks a lot...It's working...

  • how about a Computed Column that "computes" i.Quantity * i.Price

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

    SQLServerNewbieMCITP: Database Administrator SQL Server 2005
  • This was removed by the editor as SPAM

  • 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