How to Use RETURN : Return « Transact SQL « SQL Server / T-SQL Tutorial






RETURN [<integer value to return>]


8>    CREATE PROC spTestReturns
9>    AS
10>       DECLARE @MyMessage        varchar(50)
11>       DECLARE @MyOtherMessage   varchar(50)
12>
13>       SELECT @MyMessage = 'Hi, '
14>       PRINT @MyMessage
15>       RETURN
16>       SELECT @MyOtherMessage = 'Sorry'
17>       PRINT @MyOtherMessage
18>    RETURN
19>
20>    DECLARE @ReturnVal int
21>
22>    EXEC @ReturnVal = spMySproc
23>
24>    DECLARE @Return int
25>
26>    EXEC @Return = spTestReturns
27>    SELECT @Return
28>
29>    drop PROC spTestReturns;
30>    GO
1>
2>
3>








20.22.Return
20.22.1.RETURN is used to exit the current Transact-SQL batch, query, or stored procedure immediately.
20.22.2.RETURN also allows for an optional integer expression:
20.22.3.How to Use RETURN
20.22.4.Return statement
20.22.5.Return a table from a function
20.22.6.RETURNS a TABLE with structure
20.22.7.Assign returned value from a function to a declared variable