Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

Go Back  dBforums > Database Server Software > Sybase > Stored procedure question

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-30-08, 04:34
vertho vertho is offline
Registered User
 
Join Date: May 2008
Posts: 2
Stored procedure question

Hi,

I'd like to output the result from a query in a stored procedure.
The challenge is that the result from the query is unknown, so i'd like to iterate through the returned rows and output each field dynamically.
example:

if object_id('dbo.create_insert') is not null
drop procedure dbo.create_insert
go
create procedure dbo.create_insert(
@birthdate int
, @personnr int
, @tablename varchar(8)
)
as

declare cur_create_insert cursor for
select *
from @tablename
where birthdate = @birthdate
and personnr = @personnr


And now!
open cursor cur_create_insert
while (result has more rows)
while (there are more columns)
print column


Is this possible?

-Thomas
Reply With Quote
  #2 (permalink)  
Old 06-03-08, 11:53
bogere bogere is offline
Registered User
 
Join Date: Nov 2006
Posts: 4
try this

You can do it inside another stored proc

some thing like this
create proc test
as
declare @name

declare test1_cursor cursor for
select name from table

open test1_cursor

fetch test1_cursor into @name

while @@sqlstatus=0
begin

exec your_proc @name

fetch test1_cursor into @name

end

close test1_cursor

deallocate cursor test1_cursor
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

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