Solved

Use output parameter in a store proc

Posted on 2008-06-18
7
3,594 Views
Last Modified: 2011-08-18
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
Comment
Question by:pratikshahse
  • 4
  • 3
7 Comments
 
LVL 60

Expert Comment

by:chapmandew
ID: 21815967
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
 

Author Comment

by:pratikshahse
ID: 21816092
this does not work.
it keeps on saying

Procedure or function 'proc2' expects parameter '@var1', which was not supplied.
0
 
LVL 60

Expert Comment

by:chapmandew
ID: 21816148
post your code...
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 

Author Comment

by:pratikshahse
ID: 21816174
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
 
LVL 60

Expert Comment

by:chapmandew
ID: 21816201
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
 

Author Comment

by:pratikshahse
ID: 21816335
so if i do something like this
exec save_engine_clause_group ClauseGroupXML,@ClauseGroupID, @var = @outputval output

it says too many arguments

0
 
LVL 60

Accepted Solution

by:
chapmandew earned 500 total points
ID: 21816361
try this instead:

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

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Few best practices specific to Network Configurations to be considered while deploying a Hyper-V infrastructure. It may not be the full list, but this could be a base line. Dedicated Network: Always consider dedicated network/VLAN for Hyper-V…
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question