本文介绍了存储过程中的返回计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我写了一个存储过程来返回一个计数.但我得到了一个空值.谁能告诉我我的存储过程中的问题在哪里.
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
推荐答案
您正在将值设置到变量 @num_of_user 中.在查询后添加 select @num_of_user
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
这篇关于存储过程中的返回计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!