UPDATE statement using a view
-
Hi there I am trying to update a field in our contact table. I have a view which contains all of the contacts that i need to run the update for, my question is: How do i update a contact table but only update the contacts that are in my custom view?
-
Hi there I am trying to update a field in our contact table. I have a view which contains all of the contacts that i need to run the update for, my question is: How do i update a contact table but only update the contacts that are in my custom view?
This example is based on the AdventureWorks database;
UPDATE HumanResources.Employee
SET Title = 'updateFromView'
WHERE EmployeeID IN (SELECT EmployeeID FROM HumanResources.vEmployee)The
select
statement gets a list of ID's in the view. You can then update all the records in the table that have this particular ID. You'll need something to identify each record individually for this to work. If there isn't, then try to add the primary key to the view. If there is no primary key defined in the base-table, add an identity to fullfill this role. Good luck :)I are troll :)