Created
May 14, 2015 22:43
-
-
Save crowcoder/822e0154db95cf3a886d to your computer and use it in GitHub Desktop.
T-SQL Stored Procedure with OUTPUT Parameters
This file contains 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
/* | |
Unit Test: | |
DECLARE @id int; | |
DECLARE @FruitName_OUT NVARCHAR(50); | |
DECLARE @FruitColor_OUT NVARCHAR(50); | |
DECLARE @FruitGrowsOn_OUT int; | |
DECLARE @FruitIsYummy_OUT bit; | |
EXECUTE dbo.[GetFruitByID] 1, @FruitName_OUT OUTPUT, @FruitColor_OUT OUTPUT, @FruitGrowsOn_OUT OUTPUT, @FruitIsYummy_OUT OUTPUT | |
PRINT @FruitName_OUT; | |
PRINT @FruitColor_OUT; | |
PRINT @FruitGrowsOn_OUT; | |
PRINT @FruitIsYummy_OUT; | |
*/ | |
CREATE PROCEDURE [dbo].[GetFruitByID] | |
@id int, | |
@FruitName NVARCHAR(50) OUTPUT, | |
@FruitColor NVARCHAR(50) OUTPUT, | |
@FruitGrowsOn int OUTPUT, | |
@FruitIsYummy bit OUTPUT | |
AS | |
SET NOCOUNT ON; | |
SELECT @FruitName = [FruitName], @FruitColor = [FruitColor], @FruitGrowsOn = [FruitGrowsOn], @FruitIsYummy = [FruitIsYummy] | |
FROM [dbo].[Fruit] | |
WHERE Id = @id; | |
RETURN 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment