>UPDATE Client > SET NoProvince= > CASE > WHEN (SELECT COALESCE((SELECT TOP 1 Invoice.AddUser FROM Invoice > WHERE Invoice.NoClient=Client.Numero AND Invoice.NoItem=23 > ORDER BY Invoice.AI DESC),0))<>1 THEN AddUser ELSE 0 > END >>
;with cte as (select client.*, inv.AddUser as newUser, Inv.NoItem, row_number() over (partition by Inv.NoClient order by Inv.Al DESC) as Rn from Client inner join Invoice inv on Client.Numero = Inv.NoClient) update cte set NoProvince = newUser where Rn = 1 and NoItem = 23