473,406 Members | 2,208 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Loop on results, call sproc

jkmyoung
2,057 Expert 2GB
Hi,
I'm looking for a way to loop on a set of temporary results and run a stored procedure on each row of the results.

Simplified code of what I'm trying to do:
Expand|Select|Wrap|Line Numbers
  1. Declare @TMP TABLE
  2. (
  3. field1 Int
  4. field2 Int
  5. )
  6.  
  7. INSERT INTO @TMP
  8. SELECT id, otherVar
  9. from ....blah join blah join blah
  10. where bar = foo
  11.  
  12.  
  13. Declare @RC = int
  14. -- Want to loop here.
  15. For each result.
  16. Exec @RC = [Process].[dbo].[usp.storedProc1]   **field1** **field2**
  17. End for
  18.  
What is the syntax to do this? Also is this terminology correct, or is there another specific word for what I'm looking for?
Sep 18 '08 #1
1 1107
jkmyoung
2,057 Expert 2GB
Finally managed to find a solution:
Expand|Select|Wrap|Line Numbers
  1. Declare @TMP TABLE
  2. (
  3. field1 Int
  4. field2 Int
  5. )
  6.  
  7. INSERT INTO @TMP
  8. SELECT id, otherVar
  9. from ....blah join blah join blah
  10. where bar = foo
  11.  
  12.  
  13. Declare @RC = int
  14. Declare @f1 = int
  15. Declare @f2 = int
  16. declare cur_1 cursor for select field1, field2 from @TMP
  17.  
  18. -- like a do-while
  19. fetch next from cur_1 into @f1, @f2;
  20. while @@FETCH_STATUS = 0
  21. begin
  22.     Exec @RC = [Process].[dbo].[usp.storedProc1]   @f1, @f2
  23.     fetch next from cur_1 into @f1, @f2;
  24. end 
  25. close cur_1;
  26.  
Sep 18 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Radu | last post by:
Hi. It seems to be very simple, actually, but I don't know if it is feasible in TSQL. I have a sproc which gathers in one place many calls to different other sprocs, all of them taking a...
6
by: Sam | last post by:
I had created stored procedure at SQL Server 2000 and how do I call it via ASP.Net using VB Language? CREATE PROCEDURE STK As if exists (select * from dbo.sysobjects where id =...
4
by: D. Shane Fowlkes | last post by:
I've decided to send weekly emails to registered users ("members") on one of my sites. This will be the first time I attempted anything like this. Now I know I could use some 3rd party list...
73
by: Claudio Grondi | last post by:
In the process of learning about some deeper details of Python I am curious if it is possible to write a 'prefix' code assigning to a and b something special, so, that Python gets trapped in an...
7
by: Jerry | last post by:
I'm trying to execute a stored procedure in a loop while paging through database table records but the stored procedure isn't running. I get the folowing error: The component 'adodb.connection'...
22
by: silversurfer2025 | last post by:
Hello everybdy, I am a little confused for the following reason: In my code I used a simple for-loop in order to initialize a 2D-array of floats to zero. Because of efficiency reasons, I changed...
0
by: seevion | last post by:
My first post (beginner).. I hope it is clear enough and appreciate your taking the time to consider helping. I have an existing sproc that takes a cart transaction from a table and inserts shared...
1
by: pantagruel | last post by:
Hi, I have an array like the following: for(x=0;x<results.length;x++){ alert(results.length); extracted=results.shift(); alert(results.length); if(results.indexOf(extracted)== -1){
0
blyxx86
by: blyxx86 | last post by:
Good morning, I am trying to improve the efficiency of this code, I'm not sure if it can be done. The requirement is that I use two SQL statements that I pass into two ($result, $result2)...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.