0

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?

1 Answer 1

4

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
Sign up to request clarification or add additional context in comments.

1 Comment

Perfect. Thanks a lot.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.