Select record 101 to 200 ???

J

Joe M

Hi I can do a select top 100 records from a table. But how do I do a
select top 101 to 200 records from a table?? Thanks

SELECT TOP 100 Names from tableDetails

how do I do 101 to 200???
 
C

Chris2

Joe M said:
Hi I can do a select top 100 records from a table. But how do I do a
select top 101 to 200 records from a table?? Thanks

SELECT TOP 100 Names from tableDetails

how do I do 101 to 200???

Example Table

CREATE TABLE CalendarYear
(CalendarDate DATETIME
,CONSTRAINT pk_CalendarYear PRIMARY KEY (CalendarDate)
)

Sample Data

01/01/2005 0:00:01
..
..
..
12/31/2005 0:00:01


Query 1: Selects first 100

SELECT TOP 100 *
FROM CalendarYear


Query 2: Selects 101-200

SELECT TOP 100 *
FROM CalendarYear
WHERE CalendarDate NOT IN
(SELECT TOP 100 *
FROM CalendarYear);

This query produces:

04/11/05 0:00:01 <--101st Day of Year
..
..
..
07/19/05 0:00:01 <--200th Day of Year
 
S

saglamtimur

SELECT TOP 100 Id
FROM Table1
WHERE Id in (SELECT TOP 200 Id
FROM Table1
ORDER BY Id DESCENDING)
ORDER BY Id ASCENDING

Hope works for you.
 
B

Bob Barrows [MVP]

I'm not the one with the problem ...
saglamtimur said:
SELECT TOP 100 Id
FROM Table1
WHERE Id in (SELECT TOP 200 Id
FROM Table1
ORDER BY Id DESCENDING)
ORDER BY Id ASCENDING

Hope works for you.


"Bob Barrows [MVP]" <[email protected]> wrote in message
 
A

Alejandro Mesa

Use the primary key to rank the rows in your table.

Example:

use northwind
go

select
*
from
orders as a
where
(select count(*) from orders as b where b.orderid <= a.orderid) between 101
and 200
go


AMB
 
Top