Avatar of HemlockPrinters
HemlockPrinters
 asked on

how to pass one stored procedure's result as another stored procedure's parameter

First Stored Procedure SP1 has one parameter @job
Second Stored Procedure SP2 has one parameter @estno

executer SP1 @job will return the value of SP2 parameter, @estno = execute so1, @job

How can I create a new Stored procedure SP3, SP3 has one parameter @job, it will pass (executer SP1 @job) to @estno in SP2, and return the result of SP2

thanks
Microsoft SQL Server 2005

Avatar of undefined
Last Comment
Aneesh

8/22/2022 - Mon
Aneesh

>executer SP1 @job will return the value of SP2 parameter, @estno = execute so1, @job
I am not sure how you are returning the value, if you are usind a return () option, execute the sp like this
declare @ret int
Exec @ret=  execute SP1 @job
exec so1 @ret

other option will be to return the result as an output parameter
http://msdn.microsoft.com/en-ca/library/ms187004(v=sql.105).aspx
HemlockPrinters

ASKER
Thanks, I still ddin't get the result.
SP1:


Alter PROCEDURE LjobToEstno
            @Ljob int

AS
BEGIN
      -- SET NOCOUNT ON added to prevent extra result sets from
      -- interfering with SELECT statements.
      SET NOCOUNT ON;

    -- Insert statements for procedure here
      SELECT estno from bbjthead where ljob=@ljob

END


-----------------------------------------------------------------------------------------------------------------------------------

SP2:

ALTER PROCEDURE [dbo].[cq_est_estdetail_header_sp4]
      @tcEstNo      int = 0

AS

SELECT
      aajthead.estno,
      esttype,
      rolljob,
      rolldate,
......

---------------------------------------------------------------------------------------------------------------

now I created SP3:

create PROCEDURE [dbo].[cq_est_estdetail_header_sp5]
    @ljob int
    ,@tcEstNo int
AS
Exec @tcEstNo = ljobtoestno @ljob

SELECT
      aajthead.estno,
      esttype,
      rolljob,
      rolldate,
......

---------------------------------------------------------------------------------------------------------------
When I execute sp3, it still wants me to provide the value of @tcEstNo
ASKER CERTIFIED SOLUTION
Aneesh

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
HemlockPrinters

ASKER
thanks, it works great!
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
Aneesh

EXEC @tcEstNo = LjobToEstno @Ljob   ----This returns right value
select @tcEstNo
  EXEC [cq_est_estdetail_header_sp4] @tcEstNo    ---doesn't seem work,  0 value passed to @tcEstNo  -- if ir is returning 0, put a print statement inside the sp, to see whether you are assigning a value 0 to that variable