Solved

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

Posted on 2012-03-25
2
328 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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

828 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