Friday, February 26, 2010

Using OUTPUT variables in PROCEDURE

CREATE PROCEDURE dbo.GetCountByLastName
(
@LastName NVARCHAR(50),

@LastNameCount INT OUTPUT )

AS

SELECT @LastNameCount = COUNT(*) FROM Person.Contact

WHERE LastName = @LastName

Now we call this procedure as

DECLARE @TheCount INT

EXEC dbo.GetCountByLastName

@LastName = 'Senthil',

@LastNameCount = @TheCount OUTPUT

SELECT TheCount = @TheCount

No comments:

Post a Comment