SQL-Server

Moderators: None (Apply to moderate this forum)
Number of threads: 423
Number of posts: 776

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
procedure having output as cursor Posted by sikkilam on 6 Aug 2004 at 6:07 AM
i have a requirement where in the procedure has cursor as output.
i want an example of a procedure with cursor as output and how to execute the procedure. please help me out
regards
kiran

Report
Re: procedure having output as cursor Posted by elko72 on 13 Aug 2004 at 3:55 AM
: i have a requirement where in the procedure has cursor as output.
: i want an example of a procedure with cursor as output and how to execute the procedure. please help me out
: regards
: kiran
:
:
I have used this code before and it has worked for me.
See if it is any use to you.


CREATE procedure UseCursor
as
begin
set nocount on

--this table is used to store all the results for output
create table #resultsfinal
(Ref_1 char(5) not null,
Ref_2 char(5) not null,
Field_1 char(5) not null,
Field_2 char(5) not null,
Field_3 char(5) not null,)


declare @Ref_1 varchar(12)
declare @Ref_2 varchar(12)

-- this cursor is used to get a list of references from you Reference Table
declare Reflist_cur cursor
FOR SELECT Reference_1,Reference_2
FROM TblReference

-- this gets the list of References
open Reflist_cur

-- this line gets the first record from the cursor
fetch next from Reflist_cur into @Ref_1, @Ref_2

-- check the references that are returned bt the cursor
while (@@fetch_status <> -1)
begin
if (@@fetch_status <> -2)
begin
Insert into #resultsfinal(Ref_1, Ref_2, Field_1, Field_2, Field_3)
exec Store Procedure @Ref_1e, Ref_2
--This store procedure is selecting you reference info based on parameters
--being sent ot Store procedure
end
fetch next from Reflist_cur into @Ref_1, @Ref_2 end
close Reflist_cur
deallocate Reflist_cur

set nocount on

select Ref_1, Ref_2, Field_1, Field_2, Field_3
from #resultsfinal
end



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.