[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

nested stored procedures

Posted on 2006-06-29
3
Medium Priority
?
233 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

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

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

I have a large data set and a SSIS package. How can I load this file in multi threading?
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

656 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