1、创建users表:
CREATE TABLE users
(
id INT PRIMARY KEY not null IDENTITY,
name VARCHAR(22),
pwd VARCHAR(33)
)
2、插入几条数据:
INSERT INTO users VALUES('a','aaaaa'),('b','bbbbb'),('c','ccccc');
3、创建存储过程:
CREATE PROCEDURE proc_sql ---存储过程执行后,如果要修改存储过程,将CREATE改为ALTER;
@user VARCHAR(22),
@pswd VARCHAR(33),
@msg VARCHAR(50) OUTPUT
AS
BEGIN
DECLARE @num1 INT,@num2 INT;
SELECT @num1=COUNT(*) FROM users WHERE name=@user;
IF @num1>=1
BEGIN
SELECT @num2=COUNT(*) FROM users WHERE name=@user AND pwd=@pswd;
IF @num2>=1
BEGIN
SET @msg='用户名和密码输入正确';
END
ELSE
BEGIN
SET @msg='密码输入不正确';
END
END
ELSE
BEGIN
SET @msg='用户名输入不正确';
END
END
4、执行存储过程:
DECLARE @msg VARCHAR(50);
EXEC proc_sql '1','aaaaa',@msg OUTPUT;
SELECT @msg AS 信息;
5、结果:
信息
用户名输入不正确