我想实现这样的一种模糊查询,就好想搜索引擎那种假设我输入了“课本”希望得到的结果“语文课本”,“数学课本”,“上课本来就很无聊”请大虾们赐教...~~

解决方案 »

  1.   

    select * 
    from tb
    where charindex('课本',字段名)>0
      

  2.   

    select * 
    from tb
    where 字段名 like '%课本%'
      

  3.   

    select * 
    from tb
    where col like '%课本%'
      

  4.   

    select * 
    from tb
    where patindex('%课本%',字段)>0
      

  5.   

    select * 
    from tb
    where patindex('%课本%',col)>0
      

  6.   

    select * 
    from tb
    where 字段名 like '%大%树%'
      

  7.   

    select * 
    from tb 
    where 字段名 like '%大%树%'
    --or
    select * 
    from tb
    where patindex('%课%本%',字段)>0
      

  8.   

    前台进来不是declare @dashu char(4)...
    怎样%大%树%啊...
      

  9.   

    select * 
    from tb
    where patindex('%[大树]%',字段)>0
      

  10.   

    发现没什么反应的说...难道是我太笨了....定义字段@mc
    想在列XMmc中相似的数据,就是我说的那种效果
      

  11.   

    declare @dashu char(4)
    set @dashu='大树'
    select * 
    from tb
    where patindex('%['+@dashu+']%',字段)>0
      

  12.   

    OMG~~~Fantasy~~
    全部都符合了...
      

  13.   


    ---------------------------------
    --  Author: htl258(Tony)
    --  Date  : 2009-07-31 22:23:13
    ---------------------------------
    --> 生成测试数据表:tbIf not object_id('[tb]') is null
    Drop table [tb]
    Go
    Create table [tb]([TEXT] nvarchar(4))
    Insert tb
    Select '一大颗树' union all
    Select '大中华' union all
    Select '百年树木'
    Go
    --Select * from tb-->SQL查询如下:
    create function f_getstr(@s nvarchar(200))
    returns nvarchar(4000)
    as
    begin
      declare @r nvarchar(4000)
      while len(@s)>0
      begin
        set @r=isnull(@r+'%','')+left(@s,1)
        set @s=stuff(@s,1,1,'')
      end
      return @r
    end
    godeclare @dashu char(4)
    set @dashu='大树'
    select * 
    from tb
    where [TEXT] like '%'+ dbo.f_getstr(@dashu)+'%'/*
    TEXT
    ----
    一大颗树(1 行受影响)
    */