简体   繁体   English

如何在Access数据库文本字段中搜索子字符串

[英]How to search an Access database text field for a substring

I have looked through several pages and not been able to find what I need. 我浏览了几页,却找不到我需要的东西。 What I found has gotten me something that "works" but not the way I want it to. 我发现的东西给了我一些“有效”的东西,但并非我想要的那样。

SELECT p.ProductName, p.QuantityPerUnit, s.CompanyName, c.CategoryName
FROM Products AS p, Suppliers AS s, Categories AS c
WHERE p.QuantityPerUnit LIKE "*" & [500 g] & "*" AND p.SupplierID = s.SupplierID AND p.CategoryID = c.CategoryID
ORDER BY p.ProductName;

When I run this on the Access DB a window pops up for text to be entered. 当我在Access DB上运行此窗口时,会弹出一个窗口,供您输入文本。 It has 500 g as the label. 它的标签为500克。 If I put 500 g in the text field, the query works. 如果我在文本字段中放入500克,则查询有效。 What I want is to be able to run the query using 500 g as the substring to find with out user interaction. 我想要的是能够使用500 g作为子字符串来运行查询,以在没有用户交互的情况下进行查找。 I know I am close but am unsure what is incorrect. 我知道我已经接近了,但是不确定什么是错误的。

I was able to figure this out. 我能够弄清楚这一点。 The problem was the "[]". 问题是“ []”。 I switched them to single '' and it ran displaying the expected data with out requiring user intervention. 我将它们切换为单个“”,并且它在不需要用户干预的情况下显示了预期的数据。

WHERE p.QuantityPerUnit LIKE "*" & '500 g' & "*"

Thank you for taking the time to look at my problem. 感谢您抽出宝贵的时间来研究我的问题。

The wildcard in Access is "*". Access中的通配符 “ *”。 You use the percent sign in SQL Server. 您在SQL Server中使用百分号。 Take out the brackets. 取出支架。

WHERE p.QuantityPerUnit LIKE "*500 g*" AND p.SupplierID = s.SupplierID AND p.CategoryID = c.CategoryID

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM