sql 存储过程报错。我想把它写成一个模糊搜索的存储过程。
createprocproc_SearchEmployeeNameFrom_trv_1(@Keywordvarchar(100),@OUIDuniqueidentifie...
create proc proc_SearchEmployeeNameFrom_trv_1
(
@Keyword varchar(100),
@OUID uniqueidentifier
)
as
select distinct EmployeeName, EmployeeNo, MobileNo, Email
from tbOUEmployee, tbOUOrganization
where (EmployeeName like '%'+@Keyword+'%'or EmployeeNo '%'+,@Keyword+'%')
and (tbOUEmployee.OUID = @OUID and tbOUEmployee.OUID = tbOUOrganization.OUID)
报错:消息 102,级别 15,状态 1,过程 proc_SearchEmployeeNameFrom_trv_1,第 9 行
'%' 附近有语法错误 展开
(
@Keyword varchar(100),
@OUID uniqueidentifier
)
as
select distinct EmployeeName, EmployeeNo, MobileNo, Email
from tbOUEmployee, tbOUOrganization
where (EmployeeName like '%'+@Keyword+'%'or EmployeeNo '%'+,@Keyword+'%')
and (tbOUEmployee.OUID = @OUID and tbOUEmployee.OUID = tbOUOrganization.OUID)
报错:消息 102,级别 15,状态 1,过程 proc_SearchEmployeeNameFrom_trv_1,第 9 行
'%' 附近有语法错误 展开
展开全部
declare @sql varchar(200),
SET @SQL='select distinct EmployeeName, EmployeeNo, MobileNo, Email
from tbOUEmployee, tbOUOrganization
where (EmployeeName like '%' '+@Keyword+''%'or EmployeeNo '%'+,@Keyword+'%') and (tbOUEmployee.OUID = @OUID and tbOUEmployee.OUID = tbOUOrganization.OUID) '
exec @sql
带变量的只能用扩展SQL
SET @SQL='select distinct EmployeeName, EmployeeNo, MobileNo, Email
from tbOUEmployee, tbOUOrganization
where (EmployeeName like '%' '+@Keyword+''%'or EmployeeNo '%'+,@Keyword+'%') and (tbOUEmployee.OUID = @OUID and tbOUEmployee.OUID = tbOUOrganization.OUID) '
exec @sql
带变量的只能用扩展SQL
展开全部
create proc proc_SearchEmployeeNameFrom_trv_1
(
@Keyword varchar(100),
@OUID uniqueidentifier
)
as
declare @mysql varchar(5000)
set @mysql=N'select distinct EmployeeName, EmployeeNo, MobileNo, Email
from tbOUEmployee, tbOUOrganization
where (EmployeeName like '%''+@Keyword+''%'or EmployeeNo '%''+@Keyword+''%')
and (tbOUEmployee.OUID ='+@OUID+' and tbOUEmployee.OUID = tbOUOrganization.OUID)'
exec (@sql)
只能用动态执行
(
@Keyword varchar(100),
@OUID uniqueidentifier
)
as
declare @mysql varchar(5000)
set @mysql=N'select distinct EmployeeName, EmployeeNo, MobileNo, Email
from tbOUEmployee, tbOUOrganization
where (EmployeeName like '%''+@Keyword+''%'or EmployeeNo '%''+@Keyword+''%')
and (tbOUEmployee.OUID ='+@OUID+' and tbOUEmployee.OUID = tbOUOrganization.OUID)'
exec (@sql)
只能用动态执行
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
EmployeeName like '%'+@Keyword+'%'or EmployeeNo '%'+,@Keyword+'%' 少了like吧?
EmployeeName like '%'+@Keyword+'%'or EmployeeNo like '%'+,@Keyword+'%'
EmployeeName like '%'+@Keyword+'%'or EmployeeNo like '%'+,@Keyword+'%'
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询