位置: 编程技术 - 正文

sql中生成查询的模糊匹配字符串(sql查询生成器)

编辑:rootadmin
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 id=identity(int,1,1) into 序数表 from syscolumns a,syscolumns b alter table 序数表 add constraint pk_id_序数表 primary key(id) go /*--根据指定字符串生成查询的模糊匹配字符串 条件连接的关键字为 and,or 可以任意指定括号 生成的条件表达式为 like 模糊匹配 --邹建 .(引用请保留此信息)--*/ /*--调用示例 --调用示例 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(), --要检索的字符串 @fdname sysname --在那个字段中检索 )returns Nvarchar() as begin declare @r Nvarchar() 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中生成查询的模糊匹配字符串(sql查询生成器),希望有所帮助,仅作参考,欢迎阅读内容。

sql中生成查询的模糊匹配字符串(sql查询生成器)

文章相关热门搜索词:可以使用sql查询生成一个新表,sql查询生成新字段,sql生成表查询,sql查询结果生成表,可以使用sql查询生成一个新表,可以使用sql查询生成一个新表,sql查询生成器,sql生成表查询,内容如对您有帮助,希望把文章链接给更多的朋友!

将Session值储存于SQL Server中 一般情况下,我们喜欢使用Session储存我们的变量。Asp.Net提供了下面一些方法储存Session的值:InProcStateServerSQLServerInProc表示我们使用传统ASP一样的方法

使用SQL Server数据库嵌套子查询的方法 很多SQLServer程序员对子查询(subqueries)的使用感到困惑,尤其对于嵌套子查询(即子查询中包含一个子查询)。现在,就让我们追本溯源地探究这个问

SQL Server SQL Agent服务使用教程小结 1.在查询分析器理启动或停止SQLAgent服务启动usemastergoxp_cmdshell'netstartSQLSERVERAGENT'停止usemastergoxp_cmdshell'netstopSQLSERVERAGENT'将服务的启动从手工方式改为自

本文链接地址:https://www.jiuchutong.com/biancheng/348399.html 转载请保留说明!

上一篇:sql中返回参数的值(sql返回数据条数)

下一篇:将Session值储存于SQL Server中(session几种存储方式)

免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

鄂ICP备2023003026号

网站地图: 企业信息 工商信息 财税知识 网络常识 编程技术

友情链接: 武汉网站建设 电脑维修 湖南楚通运网络