I am stuck on a query to generate a temporary table having values according to the following condition.
I have a table as follows (Table1)
ID
1
5
9
3
10
I want a new record set according to the ID column value, like if I have ID=1, I need 1 row, if ID=5 I need five rows and so on in the temp table, so the out put table will look something like:
ID Val
1 Null
5 Null
5 Null
5 Null
5 Null
5 Null
and so on..
I am using two loops to achieve this, one loop is through ID and inner loop through ID value, but I believe there must be a simpler way to do this.
You could use a numbers table. Here I use spt_values that has a highest value of 2047. If that is not enough for you you should create a numbers table of your own.