Skip to content
Advertisement

Inserting Multiple of same records into SQL temp table based on value in column

So I have table with the following records:

Source table

I want to create a script to iteratively look at the Cnt_Repeat column and insert that same record in a temp table X times depending on the value in Cnt_Repeat so it would look like the following table:

Table of results

Advertisement

Answer

One method supported by most databases is the use of recursive CTEs. The exact syntax might vary, but the idea is:

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