Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Can you set off a trigger based on one column changing?
Message
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Versions des environnements
SQL Server:
SQL Server 2008
Divers
Thread ID:
01466971
Message ID:
01466976
Vues:
61
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
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform