2016-07-29 60 views
-1

我想创建一个查询来标识长文本字符串不包含任何子字符串列表的条目。MS Access变量字符串搜索

什么我是...

SELECT [other necessary data], [Long text string] 
WHERE [Long String] NOT LIKE "*[substring1]*" 
    AND [Long string] NOT LIKE "*[substring2]*" 
    AND [Long string] NOT LIKE "*[substring3]*" 

这工作得很好。然而!我希望排除的子串列表是可变的,例如项目1不包括子字符串1和3,项目2不包括子字符串2,3和17等。

有关如何执行此操作的任何建议?

+0

请演示您是如何尝试解决问题和出错的地方。了解如何提出问题http://stackoverflow.com/help – alexi2

+0

项目是您选择的表格中的一列吗? –

回答

0

也许这样?然后你只需要调用它,最多可以有四个字符串来排除和使用sql,无论你想要做什么。

Function strsql(ex1 as string,Optional ex2 as string = "", _ 
Optional ex3 as string = "", Optional ex4 as string = "") as string 
strsql = "SELECT [other necessary data], [Long text string] _ 
WHERE [Long String] NOT LIKE " & chr(34) & "*" & ex1 & "*" & _ 
chr(34) 
If ex2 <> "" then 
strsql = strsql & " AND [Long String] NOT LIKE " & chr(34) & _ 
"*" & ex2 & "*" & chr(34) 
End if 
If ex3 <> "" then 
strsql = strsql & " AND [Long String] NOT LIKE " & chr(34) & _ 
"*" & ex3 & "*" & chr(34) 
End if 
If ex4 <> "" then 
strsql = strsql & " AND [Long String] NOT LIKE " & chr(34) & _ 
"*" & ex4 & "*" & chr(34) 
End if 
strsql = strsql & ";" 
End Function