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
This is T-SQL, not C. Never use return values, many client side APIs make dealing with return values a pain if not plain impossible. Always use OUTPUT parameters.
I use return value to many things because it is more performative such as:
1 - When you insert or change an item when I do the validation in the database Return positive number to return the Identity and negative with the number of the error, it is faster.
2- When I make an appointment with paging use it to return the total amount of records is also faster and less costly. For the rest I use Output when there are several returns or different types of int. And of course I use recorset to return a list of items
How do I use the Dapper to make my queries I do not suffer.
I will answer this question in different ways:
If you would like to return one value you have both the options. But if you would like to return multiple values you only need to stick with output parameters.
Second Scenario: In C# you have the control of type if you are using output parameters.
Third scenario: Function vs. Procedure select the one suiting to your needs.
Hope this helps
Since return values only work with int
, it ends up being "inconsistent". I prefer the output param for consistency.
Also, output params force the caller to recognize the returned value. IME, return values are routinely ignored.
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.
taken from here