Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Can you set off a trigger based on one column changing?
Message
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Environment versions
SQL Server:
SQL Server 2008
Miscellaneous
Thread ID:
01466971
Message ID:
01466976
Views:
60
If the Invoices.PaymentTotal column changes during an update, I wanted the trigger to detect the change and then copy the Vendor's Name, and Address to another table from the Vendors table for the vendor for that same invoice.

OK, maybe something like this...I'm assuming the "new table" is called NewTable,and that NewTable and Vendor can be joined in some way, and invoices and vendors can be joined in some way. So something "like" the following can be done:
UPDATE <NewTable>  set NewTable.VendorName = Vendor.VendorName, NewTable.Address = vendor.Address
     from Invoices
                                         JOIN Inserted on Invoices.InvoiceKey = Inserted.InvoiceKey
                                          JOIN Deleted on Invoices.InvoiceKey = Deleted.InvoiceKey
                                           join Vendor on Invoices.VendorKey = Vendor.VendorKey
                                           join <NewTable> on NewTable.VendorKey = Vendor.VendorKey      -- i am assuming some link here
                                                where Inserted.PaymentTotal = Deleted.PaymentTotal
Previous
Reply
Map
View

Click here to load this message in the networking platform