• You're not referencing your CTE on your UPDATE statement. Additionally, you don't have anything to make a relationship (and that's caused by the previous reason).

    You don't actually need a CTE, something as simple as a JOIN should work.

    UPDATE ce SET

    FormerBranch = CASE WHEN e.EntityName IS NULL

    THEN ' '

    ELSE e.EntityName

    END

    FROM ClientExtra ce

    JOIN Clients c ON ce.ClientRef = c.ClientRef

    LEFT

    JOIN Entities e ON c.BranchRef = e.EntityRef AND e.Type = 3

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2