往存储过程中传递带百分号的参数,如:
EXEC [dbo].[G_CMS_Page] users,'','test like %Sun%','',99999
在存储过程中,需要传入这个条件:test like '%Sun%',但写在参数里,这个单引号不知道怎么处理。
谢谢。
EXEC [dbo].[G_CMS_Page] users,'','test like %Sun%','',99999
在存储过程中,需要传入这个条件:test like '%Sun%',但写在参数里,这个单引号不知道怎么处理。
谢谢。
这种方式,查询到的结果肯定是错误的.我用的是SQLSERVER2005.
EXEC [dbo].[G_CMS_Page] users,'','test like ''%Sun%''','',99999
--正常情况
select * from tablename where test like '%sum%'
--作为参数的时候用''在字符串内部表示'
--创建一个表
create table test0728(id int,col varchar(2))
insert into test0728
select 1,'aa' union all
select 2,'ca' union all
select 3,'dd' union all
select 4,'ee'
go--创建一个存储过程
create proc getinfo
(
@p varchar(20) --参数是一个条件
)
as
begin
exec('select * from test0728 where 1=1 and '+@p)
end--执行存储过程
exec getinfo 'col like ''%a%'''
/*结果
id col
----------- ----
1 aa
2 ca
*/