Solved

SQL - insert results of running exec stored procedure repeatedly against a list of users

Posted on 2012-03-25
2
325 Views
Last Modified: 2012-04-05
I have a table that will give me all the users id
Select userid from UserTable
I have a stored procedure  that will give me the user workplace given the userid as arguement.
Exec GetUserWorkSpace userid

I am trying to find out how I can loop through 'Exec GetUserWorkSpace userid' for all the userid from UserTable.  I would like to insert the result from GetUserWorkSpace into a table.

How can I write a SQL to do that?
0
Comment
Question by:tommym121
2 Comments
 
LVL 14

Accepted Solution

by:
nishant joshi earned 500 total points
ID: 37764268
you can write while loop for it
declare @tab table
declare @temp nvarchar(50)='test'
while(@temp <> '') --set @temp=userid
BEGIN
SET @tab=Execute sp_executesql N'Exec GetUserWorkSpace'+userid,N'',N''
insert into ...
select * from tab
END

Open in new window

0
 

Author Comment

by:tommym121
ID: 37764311
nishantcomp2512

Thanks for the prompt response,

Based on what you wrote,   where do I put the select userid from UserTable?
0

Featured Post

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Join & Write a Comment

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now