模糊查询的关键字

来源:互联网 发布:mac系统清理工具 编辑:程序博客网 时间:2024/04/27 07:23

模糊查询的关键字例:

ABC =====>%A%B%C%

create function fun_SearchKey(@temp varchar(50))  
------模糊查询的关键字----  
RETURNS VARCHAR(100)  
AS  
BEGIN  
DECLARE @temp1 varchar(50),@temp2 varchar(50),@i int,@x int  
set @i=len(@temp)  
set @x=1  
while(@x<=@i)  
begin  
 
set @temp1=substring(@temp,0,@x)  
 
set @temp2=substring(@temp,@x,@i)  
 
set @temp=@temp1+'%'+@temp2  
 
set @x=@x+2  
 
set @i=@i+1  
end  
set @temp=@temp+'%'  
return @temp  
END  
 
---另一种查询方式---
select * from Customers where PATINDEX('%[ab]c%',CompanyName )<>0
原创粉丝点击