模糊查询的关键字例:
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
-- ----模糊查询的关键字----
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