有一字符串,空格分开
@string='好样 没事 来了 管理'表tb
id    content
1      好样的
2      来
3      管
4      没事
5      不在
6      想要模糊查询(拆分后的字符串包含在表tb列content中的项的id)得到id
1
4
2
3谢谢

解决方案 »

  1.   

    你这个是检查string中的字段是否还在tb中呢?还是双向的?
    看你结果是双向的啊,和你问的问题不符。
      

  2.   

    单向的,就是查询与字符串分折后在表tb 中进行like
    但是我不知道用什么语好
      

  3.   

    select id
    from 表tb
    where patindex('%'+content+%, @string)>0
      

  4.   

    select id
    from 表tb
    where patindex('%'+content+'%', @string)>0
      

  5.   


    楼上的方法在@string中进行匹配,我需要@string中的字符在content中进行匹配,类似以下语句,但是需要把@string折分出来为@String1 @string2......
    select id
    from 表tb
    where content like ‘%' +@string1 +'%'
      

  6.   

    写了一个函数,把字符串拆分后成了一张表:tbstring
    item
    好样
    没事 
    来了 
    管理怎么用表tbstring中的列item 在表tb中进行模糊查询?
      

  7.   


    就是这样的匹配,相当于 好样 没事 来了 管理分别作为查询条件,如下select id
     from 表tb
     where content like ‘%好样%'
      

  8.   

    DECLARE @表tb TABLE(id smallint, content varchar(50))
    INSERT INTO @表tb (id, content)
    SELECT 1, '好样的'
    UNION SELECT 2, '来'
    UNION SELECT 3,  '管'
    UNION SELECT 4,  '没事'
    UNION SELECT 5,  '不在'
    UNION SELECT 6,  '想要'--SELECT * FROM @表tbDECLARE @tbstring TABLE(item varchar(50))
    INSERT INTO @tbstring (item)
    SELECT '好样'
    UNION SELECT '没事'
    UNION SELECT '来了'
    UNION SELECT '管理'--SELECT * FROM @tbstringSELECT id
    FROM @表tb, @tbstring
    WHERE patindex('%'+item+'%', content)>0