Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

stored procedure returns nothing

This stored procedure doesn't work. I've checked the SQL and it returns the correct value when parsed directly to the DB. It's really strange! It just returns 0 rows.

What could be wrong?

ALTER PROCEDURE dbo.GetSaltOfUser

 (
 @eMail nvarchar

 )

AS
DECLARE @result nvarchar
 /* SET NOCOUNT ON */
BEGIN
   SELECT @result = salt
   FROM UserSet
   WHERE eMail = @eMail
   RETURN @result
END
like image 630
Phil Avatar asked Oct 15 '10 22:10

Phil


1 Answers

 @eMail nvarchar

Will truncate the passed in email to one character. You need to put in a length. e.g.

  @eMail nvarchar(50)

This should match the datatype of the relevant column in UserSet

Also do you really want to be using the return code for this or do you want to use an output parameter perhaps - or just a scalar select?

ALTER PROCEDURE dbo.GetSaltOfUser

    (
    @eMail nvarchar (50),      /*Should match datatype of UserSet.eMail*/
    @salt nvarchar (50) OUTPUT /*Should match datatype of UserSet.salt*/
  )

AS
BEGIN
    SET NOCOUNT ON

    SELECT @result = salt
    FROM UserSet
    WHERE eMail = @eMail
END

And to call it

DECLARE @salt nvarchar(50)
EXECUTE dbo.GetSaltOfUser N'[email protected]', @salt OUTPUT
SELECT @salt
like image 96
Martin Smith Avatar answered Oct 08 '22 09:10

Martin Smith