Skip to content

Instantly share code, notes, and snippets.

@crowcoder

crowcoder/TSQLOutput

Created May 14, 2015
Embed
What would you like to do?
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
You can’t perform that action at this time.