Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Returning Proper Error Value 1

Status
Not open for further replies.

ewanko

Programmer
Mar 24, 2001
1
PH
hi,
i have trouble returning the right error codes. i have a stored procedure like this :

Create Procedure myproc1
...
...
INSERT INTO table1 SELECT * FROM tablesource1
IF @@ERROR < > 0 RETURN 1
...
INSERT INTO table2 SELECT * FROM tablesource2
IF @@ERROR < > 0 RETURN 2

....
INSERT INTO table6 SELECT * FROM tablesource6
IF @@ERROR < > 0 RETURN 6


i purposedly put an error on the first insert

now i tried to get the error code:
DECLARE @error_result smallint
set @error_result = EXEC @myproc1
select ' error code ',@error_result
go

results is:

error code
-6

now it seems SQL doesnt take notice of my own return values.
any help would be appreciated..

ewanko
 
Change this line:

set @error_result = EXEC @myproc1

to:

exec @error_result = @myproc1

then do a select on the @error_result:

select ' error code ',@error_result

This will do the trick.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top