CREATE PROCEDURE [icm_user_Selectuseranddepartment]
@user_textbox varchar(30),
@user_selected varchar(50)
 AS
declare @strSql varchar(500)
if(@user_selected like 'user_name') 
begin
set @strSql='select a.*,b.dept_name from icm_user a inner join icm_department b on a.dept_id=b.dept_id where a.user_name='+@user_textbox+' and a.user_delete is null' 
end
if(@user_selected like 'user_nickname') 
begin
set @strSql='select a.*,b.dept_name from icm_user a inner join icm_department b on a.dept_id=b.dept_id where a.user_nickname='+@user_textbox+'and a.user_delete is null'
end
if(@user_selected like 'dept_name') 
begin
set @strSql='select a.*,b.dept_name from icm_user a inner join icm_department b on a.dept_id=b.dept_id where b.dept_name= '+@user_textbox+' and a.user_delete is null'
end
else
begin 
set @strSql='select a.*,b.dept_name from icm_user a inner join icm_department b on a.dept_id=b.dept_id and a.user_delete is null order by user_nickname '
end 
print @strSql
exec(@strSql)
GO
不能运行,那里出错了?