一个简单的存储过程,大哥们帮忙
CREATE PROCEDURE [InsertUser]
@UName varchar(100),
@UPass varchar(100),
@Depart int
AS
declare @strMsg varchar(100)
If Exists (Select * from [User] Where UName = @UName)
begin
select @strMsg = '用户名[ '+@UName+ ']已经存在! '
end
else
begin
Insert into [User](UName,UPass,Depart) values(@UName,@UPass,@Depart)
select @strMsg = '添加用户[ '+@UName+ ']成功! '
end
return @strMsg
GO
------------------------
exec InsertUser 'eeee ', 'eeeee ',2 后返回错误
服务器: 消息 245,级别 16,状态 1,过程 InsertUser,行 18
将 varchar 值 '添加用户[eeee]成功! ' 转换为数据类型为 int 的列时发生语法错误。
[解决办法]
CREATE PROCEDURE [InsertUser]
@UName varchar(100),
@UPass varchar(100),
@Depart int
AS
declare @strMsg varchar(100)
If Exists (Select * from [User] Where UName = @UName)
begin
select @strMsg = '用户名[ '+@UName+ ']已经存在! '
end
else
begin
Insert into [User](UName,UPass,Depart) values(@UName,@UPass,@Depart)
select @strMsg = '添加用户[ '+@UName+ ']成功! '
end
print @strMsg
GO