I'm not even sure how to word this question but here goes. I need to be able to loop through a result set, within the same SQL script, and use the results in more SQL.
For example
begin
SELECT (SELECT ColumnA, ColumnB from SomeTable) as x
loop through x(
INSERT ColumnA into TableA
INSERT ColumnB into TableB
)
end
But I forget the exact way of doing this. I know I've done it before at a previous position, but I can't find the code for it in my files from that company.
Obviously, this is a very crude and basic example and I plan on doing a lot more with the result set, but I just gave this as an example.
EDIT: Here's a closer example of what I'm looking to do in case this will help.
begin
while(select columnA, columnB, columnC, columnD from myTable) as x
begin
INSERT columnA, columnB into TableA
(get newly created ID of TableA - but that's a separate question involving @@IDENTITY)
INSERT NewID, columnC, columnD into TableB
end loop
end