If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > CURSOR Question 2 - FIRST POST GOT MESSED UP!!!!!!

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-07-04, 12:12
ansonee ansonee is offline
Registered User
 
Join Date: Feb 2002
Location: Minneapolis, MN
Posts: 253
CURSOR Question 2 - FIRST POST GOT MESSED UP!!!!!!

This might sound odd but hopefully someone can shed some light on this.

I have a stored procedure thatr has three SELECT statements that are UNION'ed.

NOW it turns out the business users don't like seeing the multipole rows and just need the very first row in the cursor. For reasons I can't getinto, the UNIONS must stay (i hate my life).

Is there any way to just FETCH the first row of a CURSOR. For example:

DECLARE BONEHEAD CURSOR FOR SELECT
......
......
......

OPEN BONEHEAD CURSOR <would like to just select the first row here>

Thanks in advance!!
__________________
Anthony Robinson

"If I'm curt with you, it's because time is a factor here. I think fast, I talk fast, and I need you guys to act fast if you want to get out of this. So, pretty please - with sugar on top..."
Reply With Quote
  #2 (permalink)  
Old 10-07-04, 13:08
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
I am not sure that this will work, but you could try:

DECLARE BONEHEAD CURSOR for SELECT .... FETCH FIRST 1 ROW ONLY;

...


OPEN BONEHEAD;

Andy

Last edited by ARWinner; 10-07-04 at 13:40.
Reply With Quote
  #3 (permalink)  
Old 10-07-04, 13:41
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
I am not sure that this will work, but you could try:

DECLARE BONEHEAD CURSOR for SELECT .... FETCH FIRST 1 ROW ONLY;

...


OPEN BONEHEAD;


(I think my first post got messed up)

Andy
Reply With Quote
  #4 (permalink)  
Old 10-07-04, 16:00
ansonee ansonee is offline
Registered User
 
Join Date: Feb 2002
Location: Minneapolis, MN
Posts: 253
Tried putting the FETCH FIRST 1 ROW ONLY thing into each of the separate SELECT STATEMENTS. Would still end up returning three rows to the calling application...
__________________
Anthony Robinson

"If I'm curt with you, it's because time is a factor here. I think fast, I talk fast, and I need you guys to act fast if you want to get out of this. So, pretty please - with sugar on top..."
Reply With Quote
  #5 (permalink)  
Old 10-07-04, 16:19
ansonee ansonee is offline
Registered User
 
Join Date: Feb 2002
Location: Minneapolis, MN
Posts: 253
Got it....!!

Was putting FETCH FIRST after each SELECT. Needs to go after all of them....

Thanks AR
__________________
Anthony Robinson

"If I'm curt with you, it's because time is a factor here. I think fast, I talk fast, and I need you guys to act fast if you want to get out of this. So, pretty please - with sugar on top..."
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On