为什么这个小的存储过程无论输入什么都返回登陆成功?
create PROCEDURE MCLoginInit
(@empcode varchar(12), --操作员代码
@emppwd varchar(64), --用户输入密码
@notice varchar(150) output,
@result int output)
AS
declare @mm varchar(100)
if (@empcode is null) or (ltrim(rtrim(@empcode))= ' ')
begin
set @notice = '操作员或密码不能为空 '
set @result = -1
return --输入操作员代码为空,返回
end
select @mm = pdamm from sys_users where dm = @empcode
print(ltrim(rtrim(@empcode)))
print(@mm)
if ltrim(rtrim(@empcode)) <> @mm
goto err_exit
set @notice = '登陆成功 '
set @result = 0
return --输入操作员代码为空,返回
err_exit:
print( 'error ')
set @notice = '密码错误 '
set @result = -1
return --密码错误,返回
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
[解决办法]
--try
create PROCEDURE MCLoginInit
(
@empcode varchar(12), --操作员代码
@emppwd varchar(64), --用户输入密码
@notice varchar(150) output,
@result int output
)
AS
declare @mm varchar(100)
if (@empcode is null) or (ltrim(rtrim(@empcode))= ' ')
begin
set @notice = '操作员或密码不能为空 '
set @result = -1
return --输入操作员代码为空,返回
end
select @mm = pdamm from sys_users where dm = @empcode
print(ltrim(rtrim(@empcode)))
print(@mm)
if ltrim(rtrim(@empcode))=@mm
begin
set @notice = '登陆成功 '
set @result = 0
return --输入操作员代码为空,返回
end
else
begin
set @notice = '密码错误 '
set @result = -1
return --密码错误,返回
end
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
[解决办法]
create PROCEDURE MCLoginInit
(@empcode varchar(12), --操作员代码
@emppwd varchar(64), --用户输入密码
@notice varchar(150) output,
@result int output)
AS
declare @mm varchar(100)
if (@empcode is null) or (ltrim(rtrim(@empcode))= ' ')
begin
set @notice = '操作员或密码不能为空 '
set @result = -1
return --输入操作员代码为空,返回
end
select @mm = pdamm from sys_users where dm = @empcode
if ltrim(rtrim(@empcode)) <> @mm
goto err_exit
else
begin
set @notice = '登陆成功 '
set @result = 0
return --输入操作员代码为空,返回
end
err_exit:
print( 'error ')
set @notice = '密码错误 '
set @result = -1
return --密码错误,返回
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
[解决办法]
欧耐心不足,看不完就头疼
[解决办法]
goto err_exit 后面要加else
不然
if ltrim(rtrim(@empcode)) <> @mm
goto err_exit
这句判断不管成不成立都会继续执行后面的语句
set @notice = '登陆成功 '
set @result = 0
return --输入操作员代码为空,返回