7

我有一个查询,我想返回名称中有特定字符串的所有客户端,两边都有通配符。所以输入可能是“Smith”,我想返回所有的东西,比如“The John Smith Company”或“Smith and Bros”。我希望 [Client] 得到提示,所以我这样设置 SQL:

PARAMETERS Client Text ( 255 );
SELECT *
WHERE (((tbl_IncomingChecks.Client) Like'%' + [Client] + '%') 
ORDER BY tbl_IncomingChecks.Client;

查询未返回任何结果。请帮忙

4

4 回答 4

6

MS Access 使用 * 作为通配符而不是 %,因此您的查询将尝试匹配文字 '%' 字符。除非您使用 ADO,否则请改用 *。

http://office.microsoft.com/en-us/access-help/like-operator-HP001032253.aspx

于 2012-12-31T19:37:44.007 回答
1

我觉得您的问题出在“+”运算符上,不应该读吗

WHERE ((tbl_IncomingChecks.Client) Like Concat('%',[Client],'%')) 

这让我进入了 DB2

于 2012-12-31T19:19:47.707 回答
0

REGEXP在 MYSQL 中使用函数怎么样?

SELECT *
WHERE tbl_IncomingChecks.Client REGEXP concat('%', @Client, '%') 
ORDER BY tbl_IncomingChecks.Client;

或者只是简单地使用 @client 作为REGEXP查找包含此客户端名称的所有客户端:

SELECT *
WHERE tbl_IncomingChecks.Client REGEXP @Client
ORDER BY tbl_IncomingChecks.Client;

根据 OP 在 RDBMS 上作为 MS ACCESS 的更新

如果您有更复杂的模式,您可以Regexp在 MS Access UDF 中使用对象。但是在当前情况下,您最好使用LIKE Concat('*',@client,'*')

'-- you may even send the pattern as a parameter 
'-- you may also send all the clients into the UDF itself for matching
'-- returning a set of matched names string

Function regexpFunc(ByRef strInput As String, ByRef clientName as String) As Boolean
   Dim myRegex As New RegExp
   Dim matchSet As MatchCollection  

   With myRegex  
     .MultiLine = False  
     .Global = True  
     .IgnoreCase = False  
   End With  

   myRegex.Pattern = clientName

   If myRegex.Test(strInput) Then  
     'matching values can be collected here
     '-- Set matchSet = myRegex.Execute(strInput)
     RegexFunc = True
   Else
     RegexFunc = False           
   End If  
End Function

以下是在查询中使用上述函数的方法:

SELECT *
FROM MYTABLE
WHERE RegexpFunc(tbl_IncomingChecks.Client, "Smith") 
ORDER BY tbl_IncomingChecks.Client;
于 2012-12-31T19:14:49.693 回答
0

您没有在声明中使用 from

PARAMETERS Client Text ( 255 );
SELECT * from table
于 2012-12-31T19:22:16.677 回答