Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is from this link: <a href="http://searchsqlserver.techtarget.com/generic/0,295582,sid87_gci1207164,00.html#9" rel="nofollow noreferrer">Calling SP from SP</a></p> <ol start="9"> <li>How can I use results from one stored procedure in another?</li> </ol> <p>So long as the stored procedure produces only a single result, the technique for using the output of one stored procedure in another is pretty straightforward. The technique is to use a temporary table to hold the results of the stored procedure and an INSERT EXEC statement to execute the sproc and save the results. Once the results are in the temporary table they can be used like any other table data. Here's an example procedure that we might like to reuse:</p> <p>CREATE PROC usp_Demo_AllAuthors as</p> <pre><code>select * from pubs..authors </code></pre> <p>GO</p> <p>Now here's a stored procedure that uses the results of usp_Demo_AllAuthors:</p> <p>CREATE proc usp_Demo_SPUser as </p> <pre><code>CREATE TABLE #Authors ( au_id varchar(11) NOT NULL PRIMARY KEY CLUSTERED, au_lname varchar (40) NOT NULL , au_fname varchar (20) NOT NULL , phone char (12) NOT NULL, address varchar (40) NULL , city varchar (20) NULL , state char (2) NULL , zip char (5) NULL , contract bit NOT NULL ) -- Execute usp_Demo_AllAuthors storing the -- results in #Authors insert into #Authors exec usp_Demo_AllAuthors -- Here we use the #Authors table. This example only -- only selects from the temp table but you could do much -- more such as use a cursor on the table or join with -- other data. SELECT au_fName + ' ' + au_lname as [name] , address+', '+city+', '+state+' '+zip [Addr] from #Authors DROP TABLE #Authors </code></pre> <p>GO</p> <p>—Andrew Novick, SQL Server Expert</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload