Solved

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

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this article I will describe the Copy Database Wizard 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.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

734 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