sql server 2008 r2 - Using a Database Trigger to move a record -
i new use of database triggers want pointed in right direction here. make trigger execute on 'insert' of new invoice or 'update' of 'balancedue' of invoice
table take vendorid
in invoices
, grab vendor
row in vendors
table , move data row table shippinglabels
. got far im kinda @ loss go here.
create trigger trsetshippinglabels on tblinvoices after insert, update insert tblshippinglabels select vendorname, vendoraddress, vendorcity, vendorstate, vendorzipcode tblvendors join tblinvoices on i.vendorid = vendors.vendorid
you're pretty close. need use the special "inserted" table within trigger. table accessible within triggers (or in conjunction output clause), , holds data inserted last statement executed against relevant permanent table. there corresponding "deleted" table if wanted remove data in trigger.
create trigger trsetshippinglabels on tblinvoices after insert,update insert tblshippinglabels select vendorname, vendoraddress, vendorcity, vendorstate, vendorzipcode vendors join inserted on i.vendorid = vendors.vendorid
Comments
Post a Comment