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.

 All Forums
 Other Forums
 Other Topics
 Sorting the result set in the cursor in ascending order.

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2002-12-05 : 07:33:41
Jhankar writes "Hi,
I am facing a peculiar problem. I have to fetch the last 16 records from a db2 table.

I can fetch the last 16 records in descending order. But, my requirement is these records in Ascending order.

Currently, I have executed this code using two cursors, but this way the nbr of i/o are doubled, and it overloads my system

My first cursor (CUR 1) reads the table in descending order till i get the 16th key from bottom.
Then another cursor (CUR 2) fetches the 16 records in forward manner. So, actually I am using twice the nbr of queries.

When I try using the first fetch (CUR 1) to fetch the last 16 records from CUR 2 in ASC order the result set returns the top 16 records from my table.

And when I try using the first key of CUR 1 to fetch 16 records from the CUR 2 in DESC order I do get my set but I need to now sort this in ASC order to use it.

Is there a way to order this set in ASC w/o doing the double series of fetches?"

robvolk
Most Valuable Yak

15732 Posts

Posted - 2002-12-05 : 08:49:30
Might want to look here:

http://ourworld.compuserve.com/homepages/Graeme_Birchall/HTM_COOK.HTM

He has several Adobe PDF files with extracts from his DB2 Cookbook, page 62 of the 8.1 version has an example of retrieving rows (no use of cursors either, from what I can tell)

If that does not help, you need to post your question in a DB2 forum, SQL Team is a MS SQL Server site. You can try:

http://dbforums.com/

Go to Top of Page
   

- Advertisement -