I Have a table below and I will create a new column say named 'Amount'. The existing column 'Id' is foreign key and link the information in a table say 'Loan'('Id' is the primary key of table 'Loan' ). The simple thing I wanna do is assign each new created Amount cell with the right amount obtain from table 'Loan', mapping with 'Id'. I currently use local variable and self-created table type to find the amount value in 'Loan' case by case. Is there any other more efficient way to execute the same operation? Many thanks.
MyTable was as below:

[![enter image description here](https://i.stack.imgur.com/SmLZc.png)](https://i.stack.imgur.com/SmLZc.png)

My code was as followed:

```
ALTER TABLE MyTable
ADD Amount  MONEY

CREATE TYPE ListofID AS TABLE (idx INT IDENTITY(1,1), ID VARCHAR(255))

DECLARE @Table_ID_List  ListofID
INSERT @Table_ID_List  (
ID )
SELECT Id FROM MyTable

DECLARE @i INT
DECLARE @cnt INT
SELECT @i = min(idx) - 1, @cnt = max(idx) FROM @Table_ID_List  

DECLARE @app VARCHAR(255)

WHILE @i<@cnt

BEGIN

     SELECT @i = @i + 1
     SELECT @app = (SELECT ID FROM @Table_ID_List  WHERE idx = @i)

     UPDATE MyTable
     SET Amount =(SELECT Amount FROM Loan  WHERE Id =  @app)

     WHERE Id =  @app

END

```