0

I want to insert the resultant rows of a query into another table. How can I perform this? Kindly help.

To better understand my question I simply execute the following query where I want the value of columnA to be the value of the column of the next row of the select statement in each iteration.

while exists (Select columnA from tableA where SOMECONDITION)
begin
    insert into tableB(columnA,Value1,Value2)
end
0

2 Answers 2

3

Simply do an INSERT with SELECT:

insert into tableB select columnA, value1, value2 from tableA where SOMECONDITION
Sign up to request clarification or add additional context in comments.

Comments

0

You are complicating things, you need just insert entire projection from another table as result of a subquery:

INSERT INTO tableB SELECT columnA, Value1, Value2 FROM tableA WHERE *SOMECONDITION*;

1 Comment

The select query does not return a single row ,and value1 ,value2 are not the columns of of tableA.

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.