Break table up into multiple tables by row count?

R

Ryan Clair

Is it possible to break one table up into multiple tables by groupings
of 10?

Example:

Table A has the following information:

Some Text1
Some Text2
Some Text3
Some Text4
Some Text5
Some Text6
Some Text7
Some Text8
Some Text9
Some Text10
Some Text11
Some Text12
Some Text13
Some Text14
Some Text15
Some Text16
Some Text17
Some Text18
Some Text19
Some Text20


I'd like Table A broken up into two different tables:

Table B
Some Text1
Some Text2
Some Text3
Some Text4
Some Text5
Some Text6
Some Text7
Some Text8
Some Text9
Some Text10

Table C
Some Text11
Some Text12
Some Text13
Some Text14
Some Text15
Some Text16
Some Text17
Some Text18
Some Text19
Some Text20


Note:
Each text is unique. I don't care how they are grouped only that they
are broken up into 10's in different tables. The total amount isn't a
multiple of 10 so the last table will have less. Goal is to export
each table into a csv file so if we can automate that process as
well... awesome.

Much thanks,
Ryan
 
J

John W. Vinson

Is it possible to break one table up into multiple tables by groupings
of 10?

It's neither necessary nor a good idea.

If you're assuming that you must have a standalone table in order to do an
export, your assumption is incorrect! You can and should export from a Query
instead. You can use the TOP VALUES function to chip off ten-record chunks:

SELECT TOP 10 *
FROM yourtable
ORDER BY primarykey;

SELECT TOP 10 *
FROM yourtable
WHERE primarykey NOT IN
(SELECT TOP 10 primarykey FROM yourtable ORDER BY primarykey);

SELECT TOP 10 *
FROM yourtable
WHERE primarykey NOT IN
(SELECT TOP 20 primarykey FROM yourtable ORDER BY primarykey);

and so on... replace primarykey with the actual primary key fieldname of your
table. (If your table doesn't HAVE a primary key you may have a problem; do
you have any field which uniquely identifies a record?)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top