如果是按照常规的检索,那么应该是contains(ColName,'关键词')对吗?
但是现在问题是反过来,我的关键词是ColName里面的值,而被检索的是"关键词"也就是用户输入的字符串,这个怎么检索啊?

解决方案 »

  1.   

    declare @tb table (s varchar(50))
    insert into @tb select 'abc'
    insert into @tb select 'ab'
    insert into @tb select 'ac'select * from @tb
    where patindex('%'+s+'%','abcd')>0abc
    ab
      

  2.   

    wzy_love_sly,问题是'%'+s+'%' 我这里是字段里本来就有的值怎么办?
      

  3.   

    sql语句:select top 10 字段名 from tb_name where patindex(字段名,被查询的字符串变量)>0
    这里是指在"被查询的字符串变量"中找出包含"字段名"的值的记录
      

  4.   

    就是patindex里第一个参数,不是输入进去的,是数据表字段里本身就有的值
      

  5.   

    sorry  什么叫‘数据表字段里本身就有的值’,不就是列名吗?
      

  6.   

    那就我那样写啊 s不就是列了,declare @tb table (s varchar(50))
    insert into @tb select 'abc'
    insert into @tb select 'ab'
    insert into @tb select 'ac'
    包含在'abcd'里的有
    abc
    ab
    2个,不对吗?
      

  7.   

    表tb1
    col1 
    ab
    cd
    ef
    关键词:acdefg
    需要从表中找出来的是  cd 和 ef 
      

  8.   

    create table tb(col1 varchar(5))
    insert into tb select 'ab'
    insert into tb select 'cd'
    insert into tb select 'ef'declare @v varchar(20)
    set @v='acdefg '
    select * from tb
    where patindex('%'+col1+'%',@v)>0cd
    ef
      

  9.   

    可以是可以了
    但是速度很慢,用contains会快点吗?
      

  10.   

    contains就查列里包含字符吧,语法就那样,感觉不行吧