Solved

nested stored procedures

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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

729 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