Solved

Use output parameter in a store proc

Posted on 2008-06-18
7
3,589 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

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.
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

758 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now