RE: Selecting range of rows

RE: Selecting range of rows

 

  

Works here. Looks like you're slicing off the bottom part.

select top 2000 *
from prod.dbo.ps_personal_data
where emplid not in (select top 376 emplid
from prod.dbo.ps_PERSONAL_DATA
ORDER BY EMPLID)
ORDER BY EMPLID

Is pulling the bottom 2000..... from a 2376 row table.

-----Original Message-----
From: Edwards Ed
[mailto:mssqldba-ezmlmshield-x88099678.[Email address protected]
Sent: Tuesday, June 28, 2005 3:09 PM
To: LazyDBA Discussion
Subject: RE: Selecting range of rows

Will this work?

SELECT TOP 64999 *
FROM orders
WHERE orderid NOT IN (SELECT TOP 28001 orderID
FROM orders
ORDER BY orderID) ORDER BY orderID


________________________________

From: Edwards Ed [mailto:mssqldba-ezmlmshield-x7344036.[Email address
protected]
Sent: Tue 6/28/2005 5:54 PM
To: LazyDBA Discussion
Subject: RE: Selecting range of rows



Selecting A Range of Records (Rows) In SQL Server 2000

--Select record 1 only from the Orders table in the Northwind Database
SELECT TOP 1 * FROM orders WHERE orderid NOT IN (SELECT TOP 0 orderID
FROM orders
ORDER BY orderID) ORDER BY orderID

--Select record 2 only from the Orders table in the Northwind Database
SELECT TOP 1 * FROM orders WHERE orderid NOT IN (SELECT TOP 1 orderID
FROM orders
ORDER BY orderID) ORDER BY orderID

--Select records 11-20 from the Orders table in the Northwind Database
SELECT TOP 10 * FROM orders WHERE orderid NOT IN (SELECT TOP 10 orderID
FROM orders
ORDER BY orderID) ORDER BY orderID

--Select last record only from the Orders table in the Northwind
Database SELECT TOP 1 * FROM orders WHERE orderid NOT IN (SELECT TOP 1
orderID
FROM orders
ORDER BY orderID) ORDER BY orderID DESC

--Select last 3 record only from the Orders table in the Northwind
Database SELECT TOP 3 * FROM orders WHERE orderid NOT IN (SELECT TOP 3
orderID
FROM orders
ORDER BY orderID) ORDER BY orderID DESC



________________________________

From: Tremor Olaes [mailto:mssqldba-ezmlmshield-x78417090.[Email address
protected]
Sent: Tue 6/28/2005 5:18 PM
To: LazyDBA Discussion
Subject: Selecting range of rows



I need to select the first 65,000 rows and place it in excel, then I
need to select the rest of the records 65,000 to 93,000. How do I write
the query? I know I can write to grab "TOP 65,000, but how do I grab
the rest?



Tremor Olaes

Business Systems Analyst

Office 1-858-228-2711

Mobile 1-949-842-9171



Success



"To laugh often and much; to win the respect of intelligent people and
the affection of children; to earn the appreciation of honest critics
and endure the betrayal of false friends; to appreciate beauty, to find
the best in others; to leave the world a bit better, whether by a
healthy child, a garden patch or redeemed social condition; to know even
one life has breathed easier because you have lived. This is to have
succeeded."

-Ralph Waldo Emerson





Attention:
Any views expressed in this message are those of the individual sender,
except where the message states otherwise and the sender is authorized
to state them to be the views of any such entity. The information
contained in this message and or attachments is intended only for the
person or entity to which it is addressed and may contain confidential
and/or privileged material. If you received this in error, please
contact the sender and delete the material from any system and destroy
any copies.


---------------------------------------------------------------------
TO REPLY TO EVERBODY , PLEASE CLICK REPLY-ALL, NOT JUST REPLY Website :
http://www.LazyDBA.com To unsubscribe:
http://www.lazydba.com/unsubscribe.html





---------------------------------------------------------------------
TO REPLY TO EVERBODY , PLEASE CLICK REPLY-ALL, NOT JUST REPLY Website :
http://www.LazyDBA.com To unsubscribe:
http://www.lazydba.com/unsubscribe.html





---------------------------------------------------------------------
TO REPLY TO EVERBODY , PLEASE CLICK REPLY-ALL, NOT JUST REPLY Website :
http://www.LazyDBA.com To unsubscribe:
http://www.lazydba.com/unsubscribe.html



--
This message has been scanned for viruses and dangerous content by
MailScanner, and is believed to be clean.

Douglas County, Oregon
www.co.douglas.or.us


MS Sql Server LazyDBA home page