all groups > sql server programming > february 2005 >
You're in the

sql server programming

group:

Multiple Stored Procedure Execute Together - How?


Multiple Stored Procedure Execute Together - How? GJ
2/2/2005 10:13:01 PM
sql server programming:
Hi,

I have multiple stored procedures (SP) running in multiple databases. The
output of all the databases has same column names, same number of columns and
column types.

I want to run all these different SP's as one SP and combine the output as
one result.

I tried creating one new SP as SPAll and calling all the SP's in SPAll.
eg.

Create SPAll @Parameter int
AS
Exec SP1 @Parameter
Exec SP2 @Parameter
GO

But when I execute SPAll from 'sql server reporting services' (vs.net), it
executes and displays results from SP1 also. I want to display results from
both SP1 and SP2.

RE: Multiple Stored Procedure Execute Together - How? mark baekdal
2/2/2005 10:43:01 PM
Hello GJ.

execute the stored procedures saving the result sets to a temporary table
and then select the results from the temporary table to give you a single
result set

IE:

use Northwind
GO

set nocount on

if object_id('tempdb..#results') is not null drop table #results

create table #results(
index_name sysname,/* Index name. */
index_description varchar(210),/* Index description. */
index_keys nvarchar(2078)/* Table or view column(s) upon which the index is
built. */
)

insert #results(index_name,index_description,index_keys)
exec sp_helpindex @objname = 'dbo.Categories'


insert #results(index_name,index_description,index_keys)
exec sp_helpindex @objname = 'dbo.Customers'

select * from #results




regards,
Mark Baekdal
http://www.dbghost.com
http://www.innovartis.co.uk
+44 (0)208 241 1762
Database change management for SQL Server




[quoted text, click to view]
Re: Multiple Stored Procedure Execute Together - How? Louis Davidson
2/3/2005 12:43:55 AM
Best way, based on what you are telling us:

Create SPAll @Parameter int
AS
create table #spAllReturn
(
<columns that match procs>
)
insert into #spAllReturn
Exec SP1 @Parameter

insert into #spAllReturn
Exec SP2 @Parameter

select * from #spAllReturn
GO

--
----------------------------------------------------------------------------
Louis Davidson - drsql@hotmail.com
SQL Server MVP

Compass Technology Management - www.compass.net
Pro SQL Server 2000 Database Design -
http://www.apress.com/book/bookDisplay.html?bID=266
Note: Please reply to the newsgroups only unless you are interested in
consulting services. All other replies may be ignored :)

[quoted text, click to view]

Re: Multiple Stored Procedure Execute Together - How? Uri Dimant
2/3/2005 9:53:55 AM
GJ
create table #test
(
col ...
......
......
)

insert into #test exec sp1
insert into #test exec sp2

select * from #test

[quoted text, click to view]

AddThis Social Bookmark Button