I have a table which contains 170K of customer_numbers. How can I write a query (loop) to create 340 tables or excel files which contains 500 customer numbers each.
Thanks for your assistance in advance.
A couple of questions.
1. How do you want to split the data up into groups? Randomly?
2. Tables or excel files are two VERY different things. For excel files, I would suggest you not use SQL to do this. I would probably suggest you use a .NET language to build Excel files. If you really mean tables, then I would suggest you just use one table and assign a number to each customer_number permanently at the start of your process and then you have 340 logical files.
3. What version of SQL Server are you using? In 2005 the query to assign the numbers is pretty easy.
Something like:
SELECT customer_number, NTILE (340) Over ( order by customer_number)
into #hold
from table_which_contains_170K_customer_numbers
Or update your table:
;with tiledCustomers as
(
SELECT customer_number, NTILE (340) Over ( order by customer_number) as groupValue
FROM table_which_contains_170K_customer_numbers
)
update
set group = tiledCustomers.groupValue
from table_which_contains_170K_customer_numbers as t170
join tiledCustomers
on tiledCustomers.customer_number = t170.customer_number
|||
here's a psedou code
1. select disticnt customers
2. write a script to create an empty excel files per customer
3. create a script that will generate the script for bcp out to excel files
step 3. outputs bcp scripts so you dont need to write one for each user
4. group the scripts to 10
5. simultaneously run the 10 groups at the same time if you have a powerful box to reduce your
time to complete the task.
The idea here is to write sql server scripts that will write the scripts that you need to run.
No comments:
Post a Comment