日期:2014-05-18  浏览次数:20531 次

这里有个存储过程,为何报错,纠结求解
create proc check_username
@usercode char(16)
as
declare @retcode int , @retdesc char(80)
select @retcode=-999,@retdesc='用户名已存在'

if exists(select 1 from tbl_user where userid=@usercode)
begin
select @retcode=1,@retdesc='用户名已存在'
end
else
begin
select @retcode=0,@retdesc='用户名可以使用'
end

select @retcode as retcode,@retdesc as retdesc

------解决方案--------------------
SQL code

go
create proc check_username
@usercode char(16)
as
declare @retcode int , @retdesc char(80)
select @retcode=-999,@retdesc='用户名已存在'

if exists(select 1 from tbl where 部门=@usercode)
begin
select @retcode=1,@retdesc='用户名已存在'
end
else
begin
select @retcode=0,@retdesc='用户名可以使用'
end

select @retcode as retcode,@retdesc as retdesc

exec check_username '1'

/*
retcode    retdesc
1    用户名已存在                                                                    
*/

我的机器上测试没有报错