查询数据值满足字符串内某个条件的记录 [英] Query records where data values meet a certain criteria within string
问题描述
在field2的Access数据库中,数据值可能包含以下内容:
--- field1 ------------- field2- ------
小工具1 ----- 112398764567
小工具2 ----- 987611236789
小工具3-- --- 112345678901
小工具4 ----- 543287652345
我需要一个查询,检查字段2的字符串中的每4个字符并查看对于''1223''或'''9876''的所有实例都被找到。所以我的结果将是Widget 1,Widget 2和Widget 3记录。
通常,人们可以选择简单的搜索条件,例如:
where field2比如''* 1123 *''或''9876''。
但在我的情况下,我需要检查匹配的每4个字符,以防止拉入字符串的结果像这样: 05 11 23 87 4567
我希望这是有道理的。任何想法将不胜感激! =)
In an Access Database for field2, the data values could consist of the following:
---field1-------------field2-------
Widget 1-----112398764567
Widget 2-----987611236789
Widget 3-----112345678901
Widget 4-----543287652345
I need a query that will check every 4 characters in the string of field 2 and look for all instances of ''1223'' OR ''9876'' are found. So my results would be Widget 1, Widget 2, and Widget 3 records.
Normally, one could right a simple search criteria such as:
where field2 like ''*1123*'' or ''9876''.
However in my case, I need it to check every 4 characters for a match to prevent results from pulling in strings like this: 051123874567
I hope this makes sense. Any ideas would be much appreciated! =)
推荐答案
SQL Gang可能会提出一个更好的答案,但现在可以使用:
The SQL Gang will probably come up with a better answer, but this will work for now:
您好ADezii,感谢您的快速回复。我想避免编写中间串函数的原因是因为我正在使用的字段长度超过1600个字符。也许有一个VBA功能可以实现这一点,但是我太过于将它拼凑在一起了。
Hi ADezii, thanks for the quick reply. The reason I''m wanting to avoid writing midstring functions is because the field I''m working with is over 1600 characters long. Maybe there is a VBA function that could accomplish this, but I''m too much of a novice to piece it together.
你是说Field2最多可以有1,600个字符,你希望测试每个4个字符,连续块(1 ... 4,5..8,1000 ... 1004等)对某些值?
Are you saying that Field2 can be up to 1,600 characters long and you wish to test each 4 character, consecutive block (1...4, 5..8, 1000...1004, etc.) against some value(s)?
这篇关于查询数据值满足字符串内某个条件的记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!