Reputation: 794
I'm trying to write a "simple" INSERT comand in SQL.
INSERT TABLE_A (COLUMN_1_TABLE_A, COLUMN_2_TABLE_A, COLUMN_3_TABLE_A)
VALUES (@variable_1, @variable_2, (SELECT * FROM TABLE_B))
Now, TABLE_B has one column and a variable number of rows. How can I loop through all TABLE_B rows using its values for all the inserts?
Upvotes: 0
Views: 27
Reputation: 50163
You can use SELECT
statement with INSERT INTO . .
:
INSERT TABLE_A (COLUMN_1_TABLE_A, COLUMN_2_TABLE_A, COLUMN_3_TABLE_A)
SELECT @variable_1, @variable_2, b.COL
FROM TABLE_B b
Upvotes: 4