请帮我看看这个存储过程有什么语法问题,应该改成什么样子呢?其实,我是想如果没有用户名/密码的话返回一个0,还有别的方法吗?谢谢!
ALTER PROCEDURE IsHaveUser
(
@UserName varchar(50),
@Password varchar(50) OUTPUT
)
AS
declare @count int
SET @Password= (SELECT Password FROM UserAndPassword WHERE UserName=@UserName)
SET @count = (SELECT count(Password)
FROM (SELECT (*)
FROM UserAndPassword
WHERE UserName = @UserName))
RETURN @count
select 本就可以为变量赋值,既用set 又用select显然不对.
将SET @count = (SELECT count(Password).........
改为SELECT @count= count(Password).........
set @count = (select count(*) from userAndPassword where UserName = @UserName)
不要太多无意义的嵌套查询
应该是 SELECT @count=COUNT(Password)
Code
ALTER PROCEDURE IsHaveUser
(
@UserName varchar(50),
@Password varchar(50) OUTPUT
)
AS
DECLARE @count int
IF(NOT EXISTS(SELECT [Password] FROM UserAndPassword WHERE UserName=@UserName))
BEGIN
@count=0
END
RETURN @count