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

存储过程模糊查询
SQL code

ALTER proc proc_mohuchaxun
@strs varchar(50)
as
select * from Player where name like '%@strs%'




创建的时候说proc_mohuchaxun无效 什么原因?这样写有错吗

------解决方案--------------------
探讨
SQL code

ALTER proc proc_mohuchaxun
@strs varchar(50)
as
select * from Player where name like '%@strs%'




创建的时候说proc_mohuchaxun无效 什么原因?这样写有错吗

------解决方案--------------------
ALTER proc proc_mohuchaxun
@strs varchar(50)
as
set @strs='%'+@strs+'%'
exec sp_executesql N'select * from Player where name like @key',
N'@key nvarchar(100)',@key=@strs

拼接字符串,并利用sp_executesql进行参数化执行,以便重用执行计划。