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 2005 Forums
 Transact-SQL (2005)
 For next loop select query results

Author  Topic 

cplusplus
Aged Yak Warrior

567 Posts

Posted - 2008-12-16 : 16:29:40
How can i accumulate all the records from the for next loop....

I have the following:
DECLARE @CUR_TEMP CURSOR

SET @CUR_TEMP = CURSOR SCROLL FOR (select distinct(element_id) from tab_ccsnetelementcontracts where contractid=@contractid)


OPEN @CUR_TEMP

FETCH FIRST FROM @CUR_TEMP INTO @ElementID

select efund_id,fundid,efund_amt,element_id from Tab_ccsNetEfund where element_id=@element_id

FETCH NEXT FROM @CUR_TEMP INTO @ElementID

If the loop goes 5 times, then all of the records from each loop i want to push to the front end.

Example: if the loop goes 5 times, each iteration if it gets 5 records, then i would like to show 25 records on the front end.

Thank you very much for your help.


tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-12-16 : 16:40:17
This isn't a SQL Server question, but rather it's an application programming question. What language are you using? .NET? If so, you can put the entire thing into a data set and then each data table would contain the result set from each iteration.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

cplusplus
Aged Yak Warrior

567 Posts

Posted - 2008-12-16 : 16:45:35
Hello Tara,

Is it atleast possible to push all the data to the cursor in the SP.

Thanks.

quote:
Originally posted by tkizer

This isn't a SQL Server question, but rather it's an application programming question. What language are you using? .NET? If so, you can put the entire thing into a data set and then each data table would contain the result set from each iteration.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog


Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-12-16 : 16:46:45
I don't understand your question.

Alternatively, you could just store the data into a temp table and then return the temp table to the application rather than multiple result sets.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-12-16 : 23:39:49
Can i ask the purpose of cursor here? If you can explain what you're trying to do, we can see if there's any set based alternative soln.
Go to Top of Page
   

- Advertisement -