Solved

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

Posted on 2012-03-25
2
334 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Edgartown IT Case Study

Learn about Edgartown's quest to ensure the safety and security of the entire town's employee and citizen data. Read the case study!

Question has a verified solution.

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

I have a large data set and a SSIS package. How can I load this file in multi threading?
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
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…

690 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