Stored Procedure, when to use Output parameter vs Return variable

前端 未结 7 1483
不思量自难忘°
不思量自难忘° 2020-12-28 12:54

When would you use an output parameter vs a return variable, or vice versa? In the following simple example, I can achieve the same thing using either one.

Using out

7条回答
  •  臣服心动
    2020-12-28 13:29

    You should use RETURN to return a value from a procedure much in the same way you'd use EXIT to return a value in a batch script. Return isn't really for parameter passing, but rather as a way to quit out of a procedure or query. As per MSDN documentation:

    Unless documented otherwise, all system stored procedures return a value of 0. This indicates success and a nonzero value indicates failure.

    This becomes more evident once you recognize the lack of any ability to define a type to your return value. It has to be INT.

提交回复
热议问题