?
Solved

nested stored procedures

Posted on 2006-06-29
3
Medium Priority
?
230 Views
Last Modified: 2012-06-22
Hi

If you have a stored procedure that sets @@error and you call this procedure from inside another stored procedure, can the outer SP see the @@error set by inner procedure?

Similarly, if a nested SP calls RAISERROR, is there anyway the out SP can see the custom error message or message ID set by raise error

thanks a lot
andrea
0
Comment
Question by:andieje
[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
3 Comments
 
LVL 75

Assisted Solution

by:Aneesh Retnakaran
Aneesh Retnakaran earned 1000 total points
ID: 17010661
You need to use an output variable to pass the Error value from the inner sp

CREATE procedure innerSp @error int output
as
declare @b tinyint
if 1 =1
 
  set @b = 255+1
  SELECT @error = @@ERROR

GO
CREATE procedure mainSp
AS
  declare @error int
  exec innersp @error output
  select @@Error ,@error
0
 
LVL 40

Accepted Solution

by:
Vadim Rapp earned 1000 total points
ID: 17011086
> If you have a stored procedure that sets @@error

You mean, @@error is set by producing an error in the stored procedure. You can't type SET @@ERROR=1

> can the outer SP see the @@error set by inner procedure?

yes:

create table t1(i int not null primary key)
insert into t1 select 1
go

create procedure a as insert into t1 select 1
go

exec a
print @@error

===


prints 2627.

> Similarly, if a nested SP calls RAISERROR, is there anyway the out SP can see the custom error message or message ID set by raise error

message - no, message id - yes - the same @@error shows it.


0
 

Author Comment

by:andieje
ID: 17014120
thanks very much
andrea
0

Featured Post

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!

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Suggested Courses

764 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