Solved

nested stored procedures

Posted on 2006-06-29
3
228 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 250 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 250 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
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 backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

733 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