Hey all,
We have a database with a number of tables that have a field that needs updating. The field name is the same across all tables and the value we need to update to will also be the same across all tables.
I have the following statement that retrieves all of the tables with said field, but I'd like to know how I can update the fields as well...
I would like to do something like this (which does not work)...
Does anyone have any idea about how to do this?
Thanks
Kevin
We have a database with a number of tables that have a field that needs updating. The field name is the same across all tables and the value we need to update to will also be the same across all tables.
I have the following statement that retrieves all of the tables with said field, but I'd like to know how I can update the fields as well...
Code:
SELECT t.name AS 'TableName'
FROM sys.columns c
JOIN sys.tables t ON c.object_id = t.object_id
WHERE c.name = 'UpdatePath'
ORDER BY TableName
Code:
UPDATE TableName SET UpdatePath = 'update'
where TableName in (
SELECT t.name AS 'TableName'
FROM sys.columns c
JOIN sys.tables t ON c.object_id = t.object_id
WHERE c.name = 'UpdatePath'
ORDER BY TableName)
Thanks
Kevin