Skip to content

Instantly share code, notes, and snippets.

@crowcoder
Created May 14, 2015 22:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crowcoder/822e0154db95cf3a886d to your computer and use it in GitHub Desktop.
Save crowcoder/822e0154db95cf3a886d to your computer and use it in GitHub Desktop.
T-SQL Stored Procedure with OUTPUT Parameters
/*
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