Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
Etymon
Starting Member
6 Posts |
Posted - 2007-06-11 : 11:35:18
|
I'm trying to place records into groups of 100, so I need a query that will return records but not based upon an autonumber type field. For instance, if I had a set of records that had been sequentially numbered (by autonumber) with IDs to greater than 3,600 but there were actually only 300 IDs remaining ranging from 1 to 3600 (say the others were deleted), then I would want to use a query to make three groups of 100 of the remaining IDs.I can use SELECT TOP 100 for the first 100 records. How do I get subsequent groups of 100?It's probably obvious and I am thinking too hard.  |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-06-11 : 11:48:05
|
Next 100select top 100 * from (select top 200 * from tbl order by ID) a order by ID desc KH |
 |
|
|
Etymon
Starting Member
6 Posts |
Posted - 2007-06-11 : 12:35:15
|
Thank you khtan!I seem to be having trouble with getting the results I want.I'm running this against a Snitz board. I appear to be getting the same results from each query. Here are my queries ...Query #1:SELECT TOP 100 TOPIC_IDFROM FORUM_TOPICSORDER BY TOPIC_ID Results from Query #1:TOPIC_ID6614666666736721672367256733676967756814683768676871690269286930693769387008700970307032704570467047704870527053705470747081708571037104710571097112714171517171718871907193719572167283728572977310731673397346735373607399742974707495751675767634770277147745774678647913796480078016820182528308832083488380838684108439854086478651866186658782884088628914891789628968897790249068933393359344951395679710 Query #2:SELECT TOP 100 TOPIC_IDFROM (SELECT TOP 200 TOPIC_IDFROM FORUM_TOPICS AS NEXT_200_TOPICSORDER BY TOPIC_ID) AS FORUM_TOPICSORDER BY TOPIC_ID Results from Query #2:TOPIC_ID6614666666736721672367256733676967756814683768676871690269286930693769387008700970307032704570467047704870527053705470747081708571037104710571097112714171517171718871907193719572167283728572977310731673397346735373607399742974707495751675767634770277147745774678647913796480078016820182528308832083488380838684108439854086478651866186658782884088628914891789628968897790249068933393359344951395679710 |
 |
|
|
Etymon
Starting Member
6 Posts |
Posted - 2007-06-11 : 13:38:14
|
| Ah!!! I found my error!I had removed desc from the querySELECT TOP 100 TOPIC_IDFROM (SELECT TOP 200 TOPIC_IDFROM FORUM_TOPICS AS NEXT_200_TOPICSORDER BY TOPIC_ID) AS FORUM_TOPICSORDER BY TOPIC_ID DESC |
 |
|
|
|
|
|