I am new to SQL Server, I am trying to do something as follows.
Sample code :
SELECT ITEM_ID
FROM 'TABLE_NAME_1'
WHERE ITEM_STATUS = 'ACTIVE'
SET @ITEM_PRICE = (SELECT PRICE
FROM 'TABLE_NAME_2'
WHERE 'PRODUCT_ID' = 'ITEM_ID')
INSERT INTO 'TABLE_NAME_3' (ITEM_ID, PRICE)
VALUES (@ITEM_ID, @ITEM_PRICE)
- The first statement will return multiple rows of
ITEM_ID
- By using the
ITEM_ID
I need to select theITEM_PRICE
from another table using the second statement - By using the third statement, I need to insert the data into the third table
Here the first statement returns only one ITEM_ID
, then everything is easy to do. I f it returns multiple rows how can I do all these processes for all the ITEM_ID
which has returned by the first statement?
Actually, If the first statement returns 5 rows I need to loop 5 times.
Is it possible in SQL Server, if yes, please help me to do this