Solved

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

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SSIS with VPN COnnection 2 70
Need help how to find where my error is in UFD 6 26
Tsql query 6 20
New to SSRS, extremely slow running report. 8 19
In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
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…

785 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