日期:2014-05-19  浏览次数:20472 次

SQL 存储过程带参数,请问哪里有问题
CREATE   PROCEDURE   rs_main_user  
@name   varchar(30)  
with   encryption
  AS   select   *   from   main_users  
where   username   =   @name
go  
exec   rs_main_user

提示我没有声明变量@name,请问大家这个是咋回事,谢谢

------解决方案--------------------
exec rs_main_user 'aaa '
------解决方案--------------------
exec rs_main_user 要加参数值
------解决方案--------------------
就是嘛,没有参数肯定不对,不过在这个过程中应该判断一下是否为空
------解决方案--------------------
或者这样写

ALTER PROCEDURE rs_main_user
@name varchar(30)=NULL
with encryption
AS
if @name is null
select * from main_users
else
select * from main_users
where username = @name
go

exec rs_main_user