I need to update an existing table with data from another. My CTE is giving me correct result, but when I'm trying to update with the CTE SSMS complains on
Msg 102, Level 15, State 1, Line 13
Incorrect syntax near '.'.
or Invalid column names at the lines below:
set cm.Action.Identifier_fk = ID
set cm.ActionRequestedAction = Action
set cm.Action.apartment_fk = apartment_fk
This is the code:
Use DB;
GO
with CTE (ID,Action,Identifier_fk,apartment_fk) AS
(select a.ID, a.Action, b.Identifier_fk, m.apartment_fk
from Project.AllSent a (nolock)
left outer join cm.Action b (nolock) on a.ID=b.Identifier_fk
left Outer Join csv.Matching m (nolock) on m.Identifier_fk = a.ID
left outer join csv.Apartment p (nolock) on m.apartment_fk=p.apartment_pk
where b.Identifier_fk is NULL)
update cm.Action
set cm.Action.Identifier_fk = ID
set cm.Action.RequestedAction = Action
set cm.Action.apartment_fk = apartment_fk
from CTE c
JOIN Project.AllSent t (nolock) on t.ID=c.ID;