不太明白“是否锁定”是什么意思?如果意思是没有锁定的用户才能登录,可以试试这个(直接写的,没有验证是否有错误):create procedure P_UserLogin(
@userName nvarchar(20),
@password nvarchar(20),
@ip nvarchar(15),
}
as
if exists(select 1 from [dbo].UsersTable where 
user_Name=@userName and passwd=@password 
and Locked=0)
begin
update [dbo].UsersTable set LoginTimes=loginTimes+1,
LastLoginIP=@ip 
where user_Name=@userName
select 1 --通过验证
end
else
select 0 --未通过验证
go

解决方案 »

  1.   

    webdiyer(陕北吴旗娃) “是否锁定”  
    的意思是:如果这个用户被锁定了 就不能够登陆了 然后提示:该用户被锁定
      

  2.   

    那改成这样吧:create procedure P_UserLogin(
    @userName nvarchar(20),
    @password nvarchar(20),
    @ip nvarchar(15),
    }
    as
    declare @isLocked bit
    select @isLocked=Locked from [dbo].UsersTable where 
    user_Name=@userName and passwd=@password
    if(@isLocked is null)
    select 0 --未通过验证,注意Locked这个字段不能为null,只能为1或者0
    else
    if @isLocked=1
    select 1 --通过验证,但用户被锁定
    else
    begin
    update [dbo].UsersTable set loginTimes=loginTimes+1,
    loginIP=@ip 
    where user_Name=@userName
    select 2 --通过验证
    end
    go