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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Cursor Required?

Author  Topic 

Bunce
Starting Member

13 Posts

Posted - 2003-04-16 : 06:10:55
Hi Guys,

Haven't had much experience with Cursors but think I need one here. I have a (quite complicated) stored proc which accepts a parameter and returns a 2 columned result-set.

I wish to execute this stored proc a number of times, passing a different parameter for each. I'd like to then return all the results sets as one. So basically something like this:

************************************************
Create Table #Temp (col1 int, col2 int)

Select IDRound
From tblRound
Where UseThis = 1

For Each IDRound (in above resultset)
Insert Into #Temp Exec stp_GetResults IDRound
Next

Select * From #Temp
*************************************************

Any ideas?

TIA,
Andrew


nr
SQLTeam MVY

12543 Posts

Posted - 2003-04-16 : 06:19:25
What data type is IDRound?

declare @IDRound varchar(10)
select @IDRound = ''
while @IDRound < (select max(IDRound) from tblRound where UseThis = 1
begin
select @IDRound = min(IDRound) from tblRound where UseThis = 1 and IDRound > @IDRound

insert #Temp Exec stp_GetResults @IDRound
end



==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

Bunce
Starting Member

13 Posts

Posted - 2003-04-16 : 06:32:32
its an integer.

Thanks alot, didn't know we could use WHILE in T-SQL.

Cheers,
Andrew

Go to Top of Page
   

- Advertisement -