if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[f_Sql]') and xtype in (N'FN', N'IF', N'TF'))
drop function [dbo].[f_Sql]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[序数表]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [序数表]
GO
--为了效率,所以要一个辅助表配合
select top 1000 id=identity(int,1,1) into 序数表
from syscolumns a,syscolumns b
alter table 序数表 add constraint pk_id_序数表 primary key(id)
go
/*--根据指定字符串生成查询的模糊匹配字符串
条件连接的关键字为 and,or
可以任意指定括号
生成的条件表达式为 like 模糊匹配
--邹建 2004.08(引用请保留此信息)--*/
/*--调用示例
--调用示例
select A=dbo.f_Sql('(Web or HTML or Internet) and (Programmer or Developer)','content')
select B=dbo.f_Sql('Web or HTML or Internet','content')
select C=dbo.f_Sql('(Web and HTML)','content')
select D=dbo.f_Sql('Web','content')
--*/
--示例函数
create function f_Sql(
@str Nvarchar(1000), --要检索的字符串
@fdname sysname --在那个字段中检索
)returns Nvarchar(4000)
as
begin
declare @r Nvarchar(4000)
set @r=''
select @r=@r+case
when substring(@str,id,charindex(' ',@str+' ',id)-id) in('or','and')
then ' '+substring(@str,id,charindex(' ',@str+' ',id)-id)+' '
when substring(@str,id,1)='('
then '(['+@fdname+'] like ''%'
+substring(@str,id+1,charindex(' ',@str+' ',id)-id-1)
+'%'''
when substring(@str,charindex(' ',@str+' ',id)-1,1)=')'
then '['+@fdname+'] like ''%'
+substring(@str,id,charindex(' ',@str+' ',id)-id-1)
+'%'')'
else '['+@fdname+'] like ''%'
+substring(@str,id,charindex(' ',@str+' ',id)-id)
+'%'''
end
from 序数表
where id<=len(@str)
and charindex(' ',' '+@str,id)-id=0
return(@r)
end
go
drop function [dbo].[f_Sql]
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[序数表]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [序数表]
GO
--为了效率,所以要一个辅助表配合
select top 1000 id=identity(int,1,1) into 序数表
from syscolumns a,syscolumns b
alter table 序数表 add constraint pk_id_序数表 primary key(id)
go
/*--根据指定字符串生成查询的模糊匹配字符串
条件连接的关键字为 and,or
可以任意指定括号
生成的条件表达式为 like 模糊匹配
--邹建 2004.08(引用请保留此信息)--*/
/*--调用示例
--调用示例
select A=dbo.f_Sql('(Web or HTML or Internet) and (Programmer or Developer)','content')
select B=dbo.f_Sql('Web or HTML or Internet','content')
select C=dbo.f_Sql('(Web and HTML)','content')
select D=dbo.f_Sql('Web','content')
--*/
--示例函数
create function f_Sql(
@str Nvarchar(1000), --要检索的字符串
@fdname sysname --在那个字段中检索
)returns Nvarchar(4000)
as
begin
declare @r Nvarchar(4000)
set @r=''
select @r=@r+case
when substring(@str,id,charindex(' ',@str+' ',id)-id) in('or','and')
then ' '+substring(@str,id,charindex(' ',@str+' ',id)-id)+' '
when substring(@str,id,1)='('
then '(['+@fdname+'] like ''%'
+substring(@str,id+1,charindex(' ',@str+' ',id)-id-1)
+'%'''
when substring(@str,charindex(' ',@str+' ',id)-1,1)=')'
then '['+@fdname+'] like ''%'
+substring(@str,id,charindex(' ',@str+' ',id)-id-1)
+'%'')'
else '['+@fdname+'] like ''%'
+substring(@str,id,charindex(' ',@str+' ',id)-id)
+'%'''
end
from 序数表
where id<=len(@str)
and charindex(' ',' '+@str,id)-id=0
return(@r)
end
go
标签:
sql中生成查询的模糊匹配字符串
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
白云城资源网 Copyright www.dyhadc.com
暂无“sql中生成查询的模糊匹配字符串”评论...
更新日志
2024年10月07日
2024年10月07日
- 群星《前途海量 电影原声专辑》[FLAC/分轨][227.78MB]
- 张信哲.1992-知道新曲与精丫巨石】【WAV+CUE】
- 王翠玲.1995-ANGEL【新艺宝】【WAV+CUE】
- 景冈山.1996-我的眼里只有你【大地唱片】【WAV+CUE】
- 群星《八戒 电影原声带》[320K/MP3][188.97MB]
- 群星《我的阿勒泰 影视原声带》[320K/MP3][139.47MB]
- 纪钧瀚《胎教古典音乐 钢琴与大提琴的沉浸时光》[320K/MP3][148.91MB]
- 刘雅丽.2001-丽花皇后·EMI精选王【EMI百代】【FLAC分轨】
- 齐秦.1994-黄金十年1981-1990CHINA.TOUR.LIVE精丫上华】【WAV+CUE】
- 群星.2008-本色·百代音乐人创作专辑【EMI百代】【WAV+CUE】
- 群星.2001-同步过冬AVCD【环球】【WAV+CUE】
- 群星.2020-同步过冬2020冀待晴空【环球】【WAV+CUE】
- 沈雁.1986-四季(2012梦田复刻版)【白云唱片】【WAV+CUE】
- 纪钧瀚《胎教古典音乐 钢琴与大提琴的沉浸时光》[FLAC/分轨][257.88MB]
- 《国语老歌 怀旧篇 3CD》[WAV/分轨][1.6GB]