开发者

Is a return value of 0 always a success in stored procedures?

If a 开发者_JAVA技巧stored procedure returns a value of zero, does that always mean it was run successfully? I am using MS SQL Server 2008.


No, you can return something yourself

example

CREATE PROC pr_test AS 
SELECT 1/0

RETURN 0
GO

Now run it

DECLARE @i INT
exec @i = pr_test

SELECT @i  -- will be 0

DROP PROC pr_test

Now let's do it again without the return statement

CREATE PROC pr_test2 AS 
SELECT 1/0

GO

DECLARE @i INT
exec @i = pr_test2

SELECT @i  -- will be - 6

Better to use an output parameter to pass back statuses and or messages


An @@ERROR return value of "zero" indicates that your procedure completed without any errors.

Of course, that doesn't mean that it did what you wanted it to...

Can you be more specific about what you're looking at?


You can use the Return word to return any integer value from a Stored Procedure. That means that zero does not mean that the stored procedure was executed successfully.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜