MS Access SQL - 如何使用一个LIKE运算符搜索多个字段

时间:2017-08-16 14:15:11

标签: sql database vba ms-access

我在MS Access VBA中有一个查询

Dim search As String

"SELECT Identifier
FROM tblProjects
WHERE Identifier 
LIKE '*" & search & "*' " & _
"OR Title LIKE '*" & search & "*' " & _
"OR Regions LIKE '*" & search & "*' " & _
"OR ProjectDate LIKE '*" & search & "*' " & _
(etc)

有没有办法缩短此查询以便它使用一个LIKE运算符?几乎我想搜索每列,如果它们包含搜索值。请记住,这是使用MS Access数据库。

2 个答案:

答案 0 :(得分:2)

这样的事情可行,但我个人不明白为什么你不能拥有现有的析取逻辑......它更有意义。

SELECT Identifier
FROM tblProjects
WHERE (Identifier + '|' + Title + '|' + Regions + '|' + ...) 
    LIKE '*search_text*'

答案 1 :(得分:1)

像这样的东西,可能有用,但我赞成OR,但是水平。

select q1.id,t2.id from
(select t1.id,t1.value1 from table1 as t1 where t1.[Title]='a') as q1
left join table1 as t2 on t2.[Regions]=q1.[Title]