Which approach is better to use if I need a member (sp or func) returning 2 parameters:
CREATE PROCEDURE Test
@in INT,
@outID INT OUT,
@amount DECIMAL OUT
AS
BEGIN
...
END
or
CREATE FUNCTION Test
(
@in INT
)
RETURNS @ret TABLE (outID INT, amount DECIMAL)
AS
BEGIN
...
END
What are pros and cons of each approach considering that the result will passed to another stored procedure:
EXEC Foobar @outID, @outAmount
A table valued function can only be used within a scope of a single
SELECTstatement. It cannot performDML, catch exceptions etc.On the other hand, it can return a set which can immediately be joined with another recordset in the same query.
If you use
DMLor don’t need to use the output parameters in the set-based statements, use a stored proc; otherwise create aTVF.