Last active
January 28, 2016 04:04
-
-
Save relyky/e6565abb0a3a79771054 to your computer and use it in GitHub Desktop.
T-SQL, stored procedure, optional OUTPUT parameter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- # Can I have an optional OUTPUT parameter in a stored procedure? | |
-- ref → http://stackoverflow.com/questions/3267523/can-i-have-an-optional-output-parameter-in-a-stored-procedure | |
-- Both input and output parameters can be assigned defaults. In this example: | |
CREATE PROCEDURE MyTest | |
@Data1 int | |
,@Data2 int = 0 | |
,@Data3 int = null output | |
AS | |
BEGIN | |
PRINT @Data1 | |
PRINT @Data2 | |
PRINT isnull(@Data3, -1) | |
SET @Data3 = @Data3 + 1 | |
RETURN 0 | |
END | |
------ demo ------ | |
DECLARE @Output int | |
SET @Output = 3 | |
EXECUTE MyTest | |
@Data1 = 1 | |
,@Data2 = 2 | |
,@Data3 = @Output output | |
PRINT @Output |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment