首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

存储过程模糊查询解决方法

2012-04-20 
存储过程模糊查询SQL codeALTER proc proc_mohuchaxun@strs varchar(50)asselect * from Player where nam

存储过程模糊查询

SQL code
ALTER proc proc_mohuchaxun@strs varchar(50)asselect * 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进行参数化执行,以便重用执行计划。

热点排行