Hi,
Have submitted this before, but having and issue and want to re-evaluate my procedure.
I have nearly 200,000 bigint numbers in a table:
2005041330
2005041331
2005041332
2005041333
2005041334
2005041337
2005041338
2005041339
2005041341
2005041342
2005041343
2005041347
2005041350
2005041351
2005041352
2005041353
I am looking for a way I can group this list into ranges... like this:
BegNumber EndNumber
2005041330 2005041334
2005041337 2005041339
2005041341 2005041343
2005041347 2005041347
2005041350 2005041353
In my previous post I gathered the following query:
It's a very slow process. It seems to work with small lists < 10,000. But if I try running it on my entire 200,000 rows it will never complete even after running overnight.
I had this in SQL 2000 before, but have since upgraded to 2008 R2. Is there a better way to go about this now that I have 2008 R2?
Thanks!
Brian
Have submitted this before, but having and issue and want to re-evaluate my procedure.
I have nearly 200,000 bigint numbers in a table:
2005041330
2005041331
2005041332
2005041333
2005041334
2005041337
2005041338
2005041339
2005041341
2005041342
2005041343
2005041347
2005041350
2005041351
2005041352
2005041353
I am looking for a way I can group this list into ranges... like this:
BegNumber EndNumber
2005041330 2005041334
2005041337 2005041339
2005041341 2005041343
2005041347 2005041347
2005041350 2005041353
In my previous post I gathered the following query:
Code:
insert into #temp2
SELECT MIN(docno) AS range_start,
MAX(docno) AS range_end
FROM (
SELECT docno,
(SELECT MIN(B.docno)
FROM #temp AS B
WHERE B.docno >= A.docno
AND NOT EXISTS
(SELECT *
FROM #temp AS C
WHERE C.docno = B.docno + 1)) AS grp
FROM #temp AS A) AS T
GROUP BY grp
It's a very slow process. It seems to work with small lists < 10,000. But if I try running it on my entire 200,000 rows it will never complete even after running overnight.
I had this in SQL 2000 before, but have since upgraded to 2008 R2. Is there a better way to go about this now that I have 2008 R2?
Thanks!
Brian