I'm trying to update the Table LIQUIDITYACCOUNT using the field QUANTITY which belongs to the table STOCKACCOUNT. Both tables have foreign key CLIENT_ID.
update
lq
set
lq.AMOUNT = lq.AMOUNT + ( st.QUANTITY % @num) * @rompu
from
LIQUIDITYACCOUNT lq
inner join STOCKACCOUNT st on
lq.CLIENT_ID = st.CLIENT_ID
and
st.TITRE_ID = @id_titre
and
st.QUANTITY > 0
The table STOCKACCOUNT contains informations about STOCKS hold by a customer while the table LIQUIDITYACCOUNT contains information about cash money.
If the result of the subquery contains one row, it work. But it doesn't for multiple rows. And in this generally the case in my project since any customer can hold many shares of different stocks.
How can I make it work when the subquery returns multiple rows.