nhatnghe39 - Wednesday, April 25, 2018 12:41 AM
Before calling proc
1 - Value of @MyIdent is assigned to @OrderID, and is available for use in the proc. As it is an OUTPUT param, it can be changed by the proc.
In Proc ...
1 - INSERT into table
2 - Table IDENTITY increases
3 - @@IDENTITY is assigned latest IDENTITY value
4 - @@IDENTITY value assigned to @OrderID, and passed out
After calling proc
1 - Value of @OrderID is assigned to @MyIdent
Below is a temp proc that shows how the value can be used, and changed.CREATE PROCEDURE #TestOutParam
@ParamVal INT OUTPUT
AS
BEGIN
SELECT InputParamVal = @ParamVal;
SET @ParamVal += 10;
SELECT OutputParamVal = @ParamVal;
END;
GO
DECLARE @MyVal INT = 5;
EXEC #TestOutParam @ParamVal = @MyVal OUTPUT;
SELECT MyVal = @MyVal;
GO
DROP PROCEDURE dbo.#TestOutParam;
GO