Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Accessing records

Status
Not open for further replies.

spr

Programmer
Nov 10, 2000
12
IN
I am trying to retrieve the first 5 and the last 5 records of a table together. How do I specify the where conditions??
I can retrieve the first 5 records using "rowcount". But using the same query , how do I retrieve the last 5 records also?
 
Hi,

I am giving the way by which you can do it.

1. Count Number of rows that will affect by your query and store it in a local variable.

2. Write a cursor with your SQL

3. In body of cursor take first 5 rows based on the counter.

4. Keep on accessing the data and enable to take data flag when the cursor reaches to first row of last 5 records.

Check it out.

Bye

Pravin
 
The concept of 'first' and 'last' records does not apply to relational database servers, because data are not stored in an ordonated fashion, like in FoxPro. Depending on the ORDER BY clause, 'first' and 'last' records may be different.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top