Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Return count in Stored Procedure

I wrote a stored procedure to return a count. But I got a null value. Can anybody tell me where is the problem in my stored procedure.

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go

ALTER PROCEDURE [dbo].[ValidateUser]
@UserName varchar(50),
@Password varchar(50),
@Num_of_User int output

AS 
BEGIN
  SET NOCOUNT ON;

  SELECT @Num_of_user =COUNT(*) 
    FROM login
   WHERE username = @UserName 
     AND pw = @Password

  RETURN

END
like image 406
user637995 Avatar asked Feb 28 '11 16:02

user637995


1 Answers

you are setting the value into the variable @num_of_user. add select @num_of_user after the query

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go


ALTER PROCEDURE [dbo].[ValidateUser]
    @UserName varchar(50),
    @Password varchar(50),
    @Num_of_User int output

AS
BEGIN
    SET NOCOUNT ON;
     SELECT @Num_of_user =COUNT(*) 
         FROM login
         WHERE username=@UserName AND pw=@Password

     SELECT @Num_of_user
return
END
like image 65
atbebtg Avatar answered Sep 21 '22 04:09

atbebtg