You can try one update:
UPDATE A
SET A.vendortestcode = B.test_code
FROM testtemplate A
INNER JOIN test_code_lookup B
ON A.name = B.test_name
In addition, the way that you are doing this right now is incorrect , because you accept the TOP-1 ID and the name TOP 1 in two separate requests without ORDER BY, so it’s not sure that you accept the correct name for your identifier.
Lamak source
share