you could build the queries you want to execute for all tables meeting your criteria.
if the table has a value in the UpdateBy column, are you trying to set the CreatedByID tot eh same value?
what is the purpose of joining to the Employee table if the data is already in the target table anyway? if the data is blank in LocationMaster, your update will leave those rows null still.
Anyway, as far as building the query goes,
my example below below builds the same SQL statement you demoed for every table that has both a UpdateBy column and a CreatedByID column.
is that what you want?
it's a little wierd to want to blindly update like that...since the data is already there!
set L.UpdateBy = E.UserID,
L.CreatedByID = E.UserID
from EmployeeProfile E
inner join ' + OBJECT_NAME(T1.object_id) + ' L on E.EmployeeID=L.UpdateBy
' AS cmd
FROM sys.columns T1
INNER JOIN sys.columns T2
ON T1.object_id = T2.object_id
WHERE T1.name = 'UpdateBy'
AND T2.name = 'CreatedByID'
is this what you are really trying to do?
set UpdateBy = CreatedByID
WHERE CreatedByID IS NOT NULL
--AND UpdateBy IS NULL --?? only where it's currently blank/null?
help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!