Monday, March 12, 2012

Mid Data Point

I have a database table with 464473 records in it. The file is an opt-in
list. Each record has a unique id number which are not sequential. I need
to split the file in half or find the id number of the mid-point in the
file. At some point I might need to split the file 3 or 5 ways.
HELP. How do i find the mid-point...
I thought that "select top 232237 order by id desc" would show me the id
number. It does not. Any other techniques.William,
If the ID is not sequential and there are possibly gaps in the sequencing,
finding the mid-way point is virtually useless if you are truly trying to
access 50% of the 464,473 row table.
Consider using SET ROWCOUNT:
set rowcount 232236
insert into new_table select * from current_table
delete from current_table
set rowcount 0
"William" wrote:

> I have a database table with 464473 records in it. The file is an opt-in
> list. Each record has a unique id number which are not sequential. I nee
d
> to split the file in half or find the id number of the mid-point in the
> file. At some point I might need to split the file 3 or 5 ways.
> HELP. How do i find the mid-point...
> I thought that "select top 232237 order by id desc" would show me the id
> number. It does not. Any other techniques.
>
>|||I think some clarfications would be useful.
First of all a table isn't a file.
Secondly, what do you mean by "split the file [table?] in half"? That seems
like something quite different from "find the id number of the mid-point".
It would help if you would state your actual goal rather than hinting at
different ideas. If we know what you are trying to achieve we may be able to
suggest better alternatives.
To find the mid-point ID:
SELECT MIN(id) AS mid_point
FROM
(SELECT TOP 232237 id
FROM YourTable
ORDER BY id) AS T
However, I suspect you may be looking for something slightly different, such
as paging or sampling, to which there are likely to be different and maybe
better solutions.
David Portas
SQL Server MVP
--

No comments:

Post a Comment