生成查询的模糊匹配字符串
来源:互联网 发布:设计班徽用什么软件 编辑:程序博客网 时间:2024/05/19 17:27
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
- 生成查询的模糊匹配字符串
- 声成查询的模糊匹配字符串
- SQL 模糊查询 模糊查找 字符串匹配
- 按拼音模糊匹配查询条件的生成类
- 按拼音模糊匹配查询条件的生成类
- Google字符串模糊匹配算法,字典树模糊查询
- Google字符串模糊匹配算法,字典树模糊查询
- Google字符串模糊匹配算法,字典树模糊查询
- 字符串匹配/模糊匹配(查找/模糊查找)的算法
- 快速字符串模糊匹配--基于Horspool的模糊匹配算法
- mysql 模糊匹配带 ‘_’的查询
- C++实现的字符串模糊匹配
- C++实现的字符串模糊匹配
- SQL模糊匹配查询
- pymongo 模糊匹配查询
- 模糊匹配查询 hql
- 数据库查询模糊匹配
- ElasticSearch 模糊匹配查询
- XML简介 话题讲解人:宋文鹏
- struts2系列之1
- 程序员苦,java程序员更苦
- fprintf、printf、sprintf、fscanf、scanf、sscanf 格式化输入输出
- 关键字搜索
- 生成查询的模糊匹配字符串
- C语言的一个关键字——static
- 任务的合理调度 话题提出人:廖义林
- 翻译 项目管理艺术 3.1 揭开做软件项目计划的神秘面纱(上)
- 构件库 话题提出人:宋文鹏
- genexus 开发知识总结一
- 什么是ASP?
- 其余本次讨论话题未作总结,请大家补充
- 什么是Web2.0