Solved

Use output parameter in a store proc

Posted on 2008-06-18
7
3,596 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

 

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
Why should I virtualize?  It’s a question that’s asked often enough.  My response is usually “Why SHOULDN’T you virtualize?”
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

752 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