In this article I will explain how to create a stored procedure to return value or multiple values in SQL server.
Column Name
|
Data Type
|
Allow Nulls
|
UserId
|
int(set
identity property=true)
|
No
|
UserName
|
varchar(50)
|
Yes
|
FirstName
|
varchar(50)
|
Yes
|
LastName
|
Varchar(50)
|
Yes
|
CREATE PROCEDURE
GetUserDetails
@UserName VARCHAR(50),
@Result INT OUTPUT
AS
BEGIN
SELECT UserId FROM
UserDetails WHERE UserName=@UserName
END
|
DECLARE @UserId INT
EXEC GetUserDetails 'SureshDasari',@Result=@UserId OUTPUT
|
CREATE PROCEDURE
GetMultipleUserDetails
@UserName VARCHAR(50),
@Id INT OUTPUT,
@lName VARCHAR(50) OUTPUT
AS
BEGIN
SELECT UserId,LastName
FROM UserDetails WHERE
UserName=@UserName
END
|
DECLARE @UserId INT,@LastName VARCHAR(50)
EXEC GetMultipleUserDetails 'SureshDasari',@Id=@UserId OUTPUT, @lName= @LastName OUTPUT
|
|
If you enjoyed this post, please support the blog below. It's FREE! Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email. |
|||
Subscribe by RSS
Subscribe by Email
|
|||
|
|



Subscribe by RSS
Subscribe by Email
6 comments :
It was a very good post by you
really ur blos is very good .it is very usefull for us.
Excellent!!!!!!!!!!!!!!!!!!!!!
thanks a lot
DECLARE @UserId INT
EXEC GetUserDetails 'SureshDasari',@Result=@UserId OUTPUT
sir, i am new to this so plz tell me where to write this above query in visual studio for getting the result
THANKS BRO