Skip to content
Advertisement

Dynamically Insert into Table A Based on Row_Num from Table B

I’ve condensed some data into TableB which looks like the following:

There are 2000 unique rows in total, Row_Num from 1 to 2000, and every AreaID in this table is naturally unique as well.

I now want to insert into a blank table, TableA, which has the following columns:

The insert statement I want to use is repeats everything except for the AreaID

I was attempting some things earlier and this is a basic look at what I have that I’m hoping Stackoverflow could help me expand on:

From here I would want it to ‘loop’ through the Row_Nums, once and once only, and run the full insert query above eventually doing it for all 2000 Row_Nums.

Of course, if there is a more efficient way please let me know and I will take a look.

Thanks!

Advertisement

Answer

I think you want a cross join with a fixed list of values:

If the date range is always the same, this can be simplified a little:

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement