SQL Server 用户登录


DECLARE @UserName NVARCHAR(50),@UserPwd NVARCHAR(50),@UserCount INT

SET @UserCount=0
SET @UserName='corp001'
SET @UserPwd='E26076BA199F73EF40AB18DDA1FDE649a'

--判断当前的用户名和密码是否存在数据
SELECT @UserCount=COUNT(*) FROM ZH_USER zu  WHERE zu.USERNAME = @UserName AND zu.USERPASSWD=@UserPwd
IF @UserCount>0
--如果存在数据则查询出一条数据
SELECT * FROM ZH_USER zc WHERE zc.USERNAME = @UserName AND zc.USERPASSWD=@UserPwd
ELSE

BEGIN

--如果不存在,则看当前用户名是否存在(@UserCount的值为1 :存在,否则,不存在。)

SET @UserCount = 0
SELECT @UserCount =COUNT(*) FROM ZH_USER zu WHERE zu.USERNAME=@UserName
SELECT @UserCount
END

你可能感兴趣的:(sql,server,user)