If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Microsoft SQL Server > How to display return value from stored procedure output parameter in Query Analyzer

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old
Registered User
 
Join Date: Jun 2004
Posts: 34
How to display return value from stored procedure output parameter in Query Analyzer

I tried to display return value from stored procedure output parameter in Query Analyzer, but I do not know how to do it. Below is my stored procedure:

CREATE PROCEDURE UserLogin
(
@Email nvarchar(100),
@Password nvarchar(50),
@UserName nvarchar(100) OUTPUT
)
AS

SELECT @UserName = Name FROM Users
WHERE Email = @Email AND Password = @Password
GO

If I run the query in Query Analyzer directly, I can display @UserName:

DECLARE @UserName as nvarchar(100)

SELECT @UserName = Name FROM Users
WHERE Email = @Email AND Password = @Password

Select @UserName

But how can I display @UserName if I call stored procedure:

exec UserLogin 'email', 'password', ''

I believed it return int, right?

Thanks in advance for help.
Reply With Quote
  #2 (permalink)  
Old
Registered User
 
Join Date: Mar 2004
Posts: 80
To display UserName there is no need for an output parameter.
select statement is enough in your stored proc.
<code>
SELECT Name FROM Users
WHERE Email = @Email AND Password = @Password
</code>

TO hold the value into a variable
<code>
DECLARE @UserName nvarchar(100)
exec UserLogin @email, @password, @UserName OUTPUT
SELECT @UserName
</code>

Last edited by theguru; 07-20-04 at 10:14.
Reply With Quote
  #3 (permalink)  
Old
Registered User
 
Join Date: Jul 2004
Posts: 1
Try if this works

Try if this works:

DECLARE @UserName nvarchar(100)
EXECUTE UserLogin @Email ='', @Password='', @UserName = @UserName OUTPUT
PRINT @UserName
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On