I would like to update USER_FNM
in temporary table @Users
with values from table BAUSER
.
Table @Users
:
DECLARE @USERS TABLE
(
USER_KEY INT,
USER_FNM VARCHAR(50),
USER_LNM VARCHAR(50),
USDE_HSU DECIMAL(8,2),
[110000003] DECIMAL(8,2),
[120000002] DECIMAL(8,2),
[120000003] DECIMAL(8,2)
)
What I've already tried is this:
update @USERS
set USER_FNM = (select top(1) user_fnm from bauser where bauser.user_key = USER_KEY)
But this always return the first value from BAUSER
table. How to iterate over each row of @Users
and change USER_FNM
?