CREATE proc find_teacher_by_condition
@school varchar(5) = null,
@dept varchar(5) = null,
@username varchar(20) = null,
@chinesename varchar(20) = null
as
declare @strOP nvarchar(4000),@str1 nvarchar(4000)
select @strOP = '', @str1 = ''
set @strOP = '
select * ,cg.userflag
from
t_info ,department dept ,schooldepartment school,cg_security_user cg
where
t_info.school = school.schooldeptid and t_info.yxsh = dept.deptid
and cg.[user_name]=t_info.username
'
set @str1 = @str1 + case when @school is null or @school = '' then '' else
' and school = ' +''''+ @school+''''end
set @str1 = @str1 + case when @dept is null or @dept = '' then '' else
' and yxsh = ' +''''+ @dept +''''end
set @str1 = @str1 + case when @chinesename is null or @chinesename = '' then '' else
' and DeptName = ' +''''+ @chinesename +'''' end
set @str1 = @str1 + case when @username is null or @username = '' then '' else
' and username like ' +''''+'%'+ @username +'%'+''''end
set @strOP = @strOP + @str1
print @strOP
exec sp_executesql @strOP
return 0
GO
只搜索username的时候没结果出来~其他都可以~
能否顺便告诉下我上面的每一条的作用吗?
[此贴子已经被作者于2007-8-2 14:30:18编辑过]