Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 how to call more than proc in the main proc

Author  Topic 

shm
Yak Posting Veteran

86 Posts

Posted - 2008-10-16 : 08:18:34
hi,

i have many SP but this shld be called when one Sprocedure is executed
wt am getting as in the main proc two proc i called it is giving the result as two results..i want it shld be displayed in the single result..means the two proc wt i called that result shld come as a single result....

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-16 : 08:32:27
You should use OPENROWSET and return them as two resultsets and join based on joining columns.
it wil be like
select fields..
from (select * from OPENROWSET(....,'EXEC SP1 value1,...')t1
JOIN (select * from OPENROWSET(....,'EXEC SP2 value1,...')t2
ON t1.field1=t2.field1
....




see below

http://sqlblogcasts.com/blogs/madhivanan/archive/2007/11/26/select-columns-from-exec-procedure-name-is-this-possible.aspx
Go to Top of Page

CDP
Starting Member

2 Posts

Posted - 2008-10-16 : 13:26:13
If you want the results ontop of oneanother, as if they were coming back from one query, and if they all return the same number of columns and datatypes, you should use a UNION instead of a join.


Chris.
DBA @ The Pythian Group
www.pythian.com
Go to Top of Page

shm
Yak Posting Veteran

86 Posts

Posted - 2008-10-17 : 00:51:38
hi
thank u for reply

i tried as above mentioned but am getting error..
the sp is like this


CREATE PROCEDURE QPM_Main_Proc (@PRJ_SEQ_NO INT,@FROM_DATE DATETIME,@TO_DATE DATETIME)
AS

SELECT I_Time,Effort_On_DP
FROM
SELECT * FROM OPENROWSET('EXEC QPM_Idle_Time @PRJ_SEQ_NO ,@FROM_DATE ,@TO_DATE')
UNION
SELECT * FROM OPENROWSET ('EXEC QPM_Dp_Effort @PRJ_SEQ_NO ,@FROM_DATE ,@TO_DATE')
Go to Top of Page
   

- Advertisement -