Hello everyone,
I create the following table,
[Code]
create table ABC (a varchar unique);
[/Code]
then create the following store procedure,
[Code]
CREATE PROCEDURE [dbo].[prc_AddABC]
AS
BEGIN
INSERT INTO [dbo].[ABC]
values ('a');
SELECT @@ERROR AS ABCERROR;
END -- end of store procedure
[/Code]
After execute the procedure twice, which will cause insert duplicate value 'a' on unique column a error.
What I got from Management Studio is,
ABCERROR 2627
return value -4
My question is, why @@error is not the same as return value? what does the message and return value mean? Where could I find
related documents to read their meanings?
thanks in advance,
George
George GeorgePosted Jan 14, 2009, 10:35 PM
Thanks John!
My confusion is where does the -4 come from?
regards,
George
Guest UserPosted Jan 14, 2009, 2:45 PM
You can lookup error codes in the system table sys.messages.
You can add a statement such as "RETURN 200" to your proc and your query will return 200 or whatever value you want. You could even say RETURN @@ERROR to get the error code back to your front end without saving to use a SELECT statement.