想请问一下模糊查询的sp怎么写?
比如
@name是变量,字段name需要模糊匹配
select * from person where name like
后面怎么写呢?
谢了
[解决办法]
select * from person where name like '% '+@name+ '% '
[解决办法]
exec( 'select * from person where name like ' '% '+@name+ '% ' ' ')
[解决办法]
select * from person where name like '% '+@name+ '% '
[解决办法]
declare @str nvarchar(40)
set @str= 'zh '
select * from a where fmemo like '% '+@str+ '% '
[解决办法]
CREATE PROC PS_TEST
@NAME NVARCHAR(20)
AS
BEGIN
SET NOCOUNT ON
SELECT * FROM person WHERE [name] LIKE '% '+@NAME+ '% '
SET NOCOUNT OFF
END
GO
EXEC PS_TEST '义 '
DROP PROC PS_TEST
[解决办法]
select * from person where name like '%[ '+@name+ ']% '
[解决办法]
declare @name char(10)
set @name= '123 '
print( 'select * from person where name like ' '% '+ltrim(rtrim(@name))+ '% ' ')
先把得到的语句print出来
[解决办法]
@AppName char(20)=null,
改為
@AppName varchar(20)=null,