Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3606
  • Last Modified:

Use output parameter in a store proc

I have two store procs : proc 1 and proc 2.

inside proc 1 i call proc 2. proc 2 has an output parameter  @var1. after running proc 2 i return back to proc 1. when i come back to proc 1 i want to use the output parameter from proc 2. can i do that. please give me an example.
0
pratikshahse
Asked:
pratikshahse
  • 4
  • 3
1 Solution
 
chapmandewCommented:
give this a go:

create proc proc2
(
@var1 int output
)
as
begin
set @var1 = 5
end
go

create proc proc1
as
begin
declare @outputval int
exec proc2 @var1 = @outputval output

select @outputval
end
0
 
pratikshahseAuthor Commented:
this does not work.
it keeps on saying

Procedure or function 'proc2' expects parameter '@var1', which was not supplied.
0
 
chapmandewCommented:
post your code...
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
pratikshahseAuthor Commented:
proc 1

CREATE PROCEDURE [dbo].[save_basedata_program]
(
      @BaseDataProgramID int Output,      
    @Description varchar(50),
      @ConsequenceGroupID      int,      
      @AttributeID int,
       @BasedataProgramTypeID int,
    @EnginePackageID int,
    @EffectiveDate    DateTime,
    @ExpirationDate DateTime,
      @DeActivateDate DateTime,
      @ClauseGroupXML xml
)

AS

BEGIN

DECLARE
      @ErrNo                int,
      @ErrMsg               varchar(255),
      @iRowCount            int,
      @ClauseGroupID            int,
      @outputval int

set @ClauseGroupID = 0
Begin Tran
if (@DeActivateDate IS NULL OR @DeActivateDate =  '1/1/1900 12:00:00 AM')

-- Call Save Clause Group
select @ClauseGroupXML
select @ClauseGroupID
exec save_engine_clause_group ClauseGroupXML,@ClauseGroupID = @outputval output
select @ClauseGroupID



proc 2


ALTER PROCEDURE [dbo].[save_engine_clause_group]

(  
   
    @ClauseGroup  xml,      
    @EngineClauseGroupID int output

      
)

AS

BEGIN

sql code

RETURN @EngineClauseGroupID
ErrorHandler:
      
      RAISERROR @ErrNo @ErrMsg
      RETURN -1
END
0
 
chapmandewCommented:
Your procedure save_engine_clause_group has two params, but you're only passing in the first one.  You'll need to pass in an XML param and then the 2nd param followed by the OUTPUT statement

0
 
pratikshahseAuthor Commented:
so if i do something like this
exec save_engine_clause_group ClauseGroupXML,@ClauseGroupID, @var = @outputval output

it says too many arguments

0
 
chapmandewCommented:
try this instead:

exec save_engine_clause_group
@ClauseGroup  = @ClauseGroupID,      
@EngineClauseGroupID = @outputval output
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now