开发者

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

开发者 https://www.devze.com 2023-03-06 08:45 出处:网络
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

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

精彩评论

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

关注公众号