Tasha Taystee Jefferson Tasha Taystee Jefferson - 13 days ago 7
SQL Question

sql server - Update Data from Another Table

My problem is:

I have 2 tables Assignment and Services
I am trying to update one column from another table's column's data like that.

UPDATE [Services]
SET
TeamID = (SELECT [AssignedTeam]
FROM [Assignment]
WHERE [ServiceName] in ([Services].[ServiceName]))
WHERE
EXISTS (
SELECT [ServiceName]
FROM [Assignment])


it does not work. can someone help me about that situation please? Thx

Answer

Update using JOIN.

Query

UPDATE t1
SET t1.[TeamID] = t2.[AssignedTeam]
FROM [Services] t1
JOIN [Assignment] t2
ON t1.[ServiceName] = t2.[ServiceName];
Comments