Results 1 to 3 of 3
  1. #1
    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.

  2. #2
    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 11:14.

  3. #3
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •