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
 General SQL Server Forums
 New to SQL Server Programming
 Loop through temp table, call sproc, do updates

Author  Topic 

Hammerklavier
Starting Member

26 Posts

Posted - 2015-03-05 : 19:13:26
Hi,

I'm trying to do something like this:

Loop through #Temp_1
-Execute Sproc_ABC passing in #Temp_1.Field_TUV as parameter
-Store result set of Sproc_ABC into #Temp_2
-Update #Temp_1 SET #Temp_1.Field_XYZ= #Temp_2.Field_XYZ
End Loop

It appears scary from a performance standpoint, but I'm not sure there's a way around it. I have little experience with loops and cursors in SQL. What would such code look like? And is there a preferable way (assuming I have to call Sproc_ABC using Field_TUV to get the new value for Field_XYZ?

Any help is greatly appreciated!

gbritton
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2015-03-05 : 21:00:31
how big can #temp1 be?
Go to Top of Page

Hammerklavier
Starting Member

26 Posts

Posted - 2015-03-06 : 09:17:26
Unfortunately, it could be rather large. There are parameters that the user can use to filter the data (the stored procedures are being used for a Crystal Report), but there could be as many as about 100,000 rows. We're thinking we may have to educate the users on how to filter things down more.
Go to Top of Page
   

- Advertisement -