有一字符串,空格分开
@string='好样 没事 来了 管理'表tb
id content
1 好样的
2 来
3 管
4 没事
5 不在
6 想要模糊查询(拆分后的字符串包含在表tb列content中的项的id)得到id
1
4
2
3谢谢
@string='好样 没事 来了 管理'表tb
id content
1 好样的
2 来
3 管
4 没事
5 不在
6 想要模糊查询(拆分后的字符串包含在表tb列content中的项的id)得到id
1
4
2
3谢谢
看你结果是双向的啊,和你问的问题不符。
但是我不知道用什么语好
from 表tb
where patindex('%'+content+%, @string)>0
from 表tb
where patindex('%'+content+'%', @string)>0
楼上的方法在@string中进行匹配,我需要@string中的字符在content中进行匹配,类似以下语句,但是需要把@string折分出来为@String1 @string2......
select id
from 表tb
where content like ‘%' +@string1 +'%'
item
好样
没事
来了
管理怎么用表tbstring中的列item 在表tb中进行模糊查询?
就是这样的匹配,相当于 好样 没事 来了 管理分别作为查询条件,如下select id
from 表tb
where content like ‘%好样%'
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