zoukankan      html  css  js  c++  java
  • 综合模糊查询 枫

    --创建函数

    create function [dbo].[m_fuzzyquery_v1]

    (

        @str nvarchar(2000)

    )  

    returns nvarchar(2000)

    as  

    begin  

           declare @count int,@i int;

           declare @newchar nvarchar(200),@nn nvarchar(300),@hh nvarchar(200)

           set @count=len(@str);set @i=1;set @nn='';

           while @i<@count+1

           begin

               set @newchar=substring(@str,@i,1)+'%'

               set @nn=@nn+@newchar;

               set @i=@i+1;

           end

        set @hh='%'+@nn

        return @hh

    end

     

    --测试数据

    declare @table table (connect varchar(30))

    insert into @table

    select '我爱程序' union all

    select '我的程序生活' union all

    select '绝对无聊的生活' union all

    select '活得好累' union all

    select '程序员的生活' union all

    select '序论' union all

    select '生机' union all

    select '生活杂志' union all

    select '我只是随便写写' union all

    select '真的是要来搜索的' union all

    select '程序员一生的活路'

     

    --普通的模糊查询

    select * from @table where connect like '%程序生活%'

    --运行结果

    /*

    connect

    ------------------------------

    我的程序生活

    */

     

    --应用函数查询

    select * from @table where connect like ( select dbo.[m_fuzzyquery_v1]('程序生活'))

    --运行结果

    /*

    connect

    ------------------------------

    我的程序生活

    程序员的生活

    程序员一生的活路

    */

  • 相关阅读:
    游戏架构草稿(1)
    蔡学镛:架构师最重视的文档
    常见拉丁字母
    图像识别学习1
    .net framework 2.0,3.0与3.5之间的关系 [转载]
    ASP.NET Session丢失问题原因及解决方案[转载]
    PLSQL 循环游标 cursor loop fetch into【转载】
    oracle case when的用法 【转载】
    Oracle to_char格式化函数 [转载]
    oracle表关联应用 【转载】
  • 原文地址:https://www.cnblogs.com/mrray/p/1992325.html
Copyright © 2011-2022 走看看