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 > Sybase > how to use a cursor for the result of stored procedure.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-30-08, 01:31
mohanrao mohanrao is offline
Registered User
 
Join Date: Apr 2008
Posts: 20
how to use a cursor for the result of stored procedure.

Hi,
If i want to iterate over the results returned from the execution of a stored procedure how can i define the cursor in a stored procedure..

declare cursor1 cursor for exec myproc

or
declare cursor1 cursor for myproc


Plzz some one help me
Reply With Quote
  #2 (permalink)  
Old 04-30-08, 04:09
mike_bike_kite mike_bike_kite is offline
vaguely human
 
Join Date: Jun 2007
Location: London
Posts: 2,519
Cursors are usually (always?) a bad idea - they cause all sorts of performance bottlenecks etc in systems. What is it you're trying to actually do with the data? can it be done with multiple updates etc?

Mike
Reply With Quote
  #3 (permalink)  
Old 04-30-08, 04:16
mohanrao mohanrao is offline
Registered User
 
Join Date: Apr 2008
Posts: 20
hi,
actually i want to iterate on the data and filter the data,which i get from the execution of stored procedure. please suggest me a solution.
Reply With Quote
  #4 (permalink)  
Old 04-30-08, 05:27
mike_bike_kite mike_bike_kite is offline
vaguely human
 
Join Date: Jun 2007
Location: London
Posts: 2,519
I'm just guessing how things are set up but perhaps one of the following:
  • Alter the original sproc and put the output in a table then just select from the table
  • Add parameters to the original sproc to optionaly restrict the final output.
  • Pass a where clause as a string to the original sproc and execute the sql dynamicaly.
That's three options for you.

Mike
Reply With Quote
  #5 (permalink)  
Old 04-30-08, 05:33
mohanrao mohanrao is offline
Registered User
 
Join Date: Apr 2008
Posts: 20
hi ,
actually here filtering means i want to iterate on each row..
for example if the query returns 10 rows..i want to get the rows from 6th to 10th something like this.
Reply With Quote
  #6 (permalink)  
Old 04-30-08, 06:02
mike_bike_kite mike_bike_kite is offline
vaguely human
 
Join Date: Jun 2007
Location: London
Posts: 2,519
Code:
declare @last_name_shown = ''

set rowcount 10
	select * from MyTable
	where name > @last_name_shown
	order by name
set rowcount 0
This will show 10 names at a time
If you set @last_name_shown to be the last name shown then it will show the next 10 names.
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