Stored procedure with output parameters and table function?

Which approach is better to use if I need a member (sp or func) that returns 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 the pros and cons of each approach, given that the result will be passed to another stored procedure:

EXEC Foobar @outID, @outAmount
+3
source share
7 answers

Function table-assessment only within the same operator can be used SELECT. It cannot execute DML, exclude exceptions, etc.

On the other hand, it can return a set that can be immediately attached to another set of records in the same query.

DML , , proc; TVF.

+3

, :-) , ... , ... ORM, ... , .

, .

.

+1

: @outID @amount.

(outID, amount) . , , , :

SELECT dbo.Test(1) AS TestValues
+1

, . , , , .

+1

- , .

, .

, SP/UDF SELECT - .. Inline Function - SQL Server , - - . , , UDF , , - .

, ; , .

+1

.

. , .

, , udf. , ... udf.

+1

, SP, TBF ( ) , .

, SQL, CURSOR ( , ).

0

Source: https://habr.com/ru/post/1738862/


All Articles