Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

SQL Loop and While to expand a record set

$
0
0

Looking for some TSQL help. I have a file with about 750K records in it. The records look something like this:

First_6_of_Phone_Number|Last_4_of_Phone_Number_Start|Last_4_of_Phone_Number_End
213555|0|9999
415555|0|9999
etc...

I used powershell to create a foreach and while loop to go through each record, then while loop it to create each phone number and insert an entire row into a new table. So for that first record it would look like this in the new table:

2135550000
2135550001
2135550002
2135550003
etc...

However by my count it will take somewhere around a half a year to finish. 

I thought maybe I could do it directly in SQL? Way past my abilities but I wonder if any of you know how? 

I would do a "select * from table" loop it somehow and for each record enter a loop while some current number is less then end. In that loop I would run an insert into newtable (Full_Phone_Number) values ('x')

Hopefully I am making sense? Any help would be overly welcomed. 


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>