I need to do a simple query, Select Statement
我需要做一个简单的查询,Select Statement
I want to search in Table all record with value "ValueA, ValueB".
我想在Table中搜索所有值为“ValueA,ValueB”的记录。
If I use this code, not work well:
如果我使用此代码,则无法正常工作:
String255 valueToFilter;
valueToFilter = 'ValueA, ValueB';
select count (RecId) from MyTable
where MyTable.Field like valueToFilter ;
But not working, I need to keep all record with value "ValueA" or "ValueB", if in the file there is value like : "ValueA, ValueC" I want to get too.
但是没有工作,我需要保留所有记录的值“ValueA”或“ValueB”,如果在文件中有值如:“ValueA,ValueC”我也想得到。
I don't know the number of values (valueToFilter).
我不知道值的数量(valueToFilter)。
Thanks!
谢谢!
1 个解决方案
#1
2
From my point of view the easiest way to accomplish this is to split your filter string:
从我的角度来看,实现这一目标的最简单方法是拆分过滤字符串:
String255 valueToFilterA = 'ValueA';
String255 valueToFilterB = 'ValueB';
;
select count (RecId) from MyTable
where MyTable.Field like valueToFilterA
|| MyTable.Field like valueToFilterB;
If you don't know the number of values you should use query
object to add ranges dynamically:
如果您不知道值的数量,则应使用查询对象动态添加范围:
Query query = new Query();
QueryRun queryRun;
QueryBuildDataSource qbds;
QueryBuildRange queryRange;
container conValues;
;
qbds = query.addDataSource(tableNum(MyTable));
for (i = 1; i <= conlen(conValues); i++)
{
queryRange = qbds.addRange(fieldNum(MyTable, Field));
queryRange.value(SysQuery::valueLike(conPeek(conValues, i)));
}
queryRun = new QueryRun(query);
info(strFmt("Records count %1", SysQuery::countTotal(queryRun)));
#1
2
From my point of view the easiest way to accomplish this is to split your filter string:
从我的角度来看,实现这一目标的最简单方法是拆分过滤字符串:
String255 valueToFilterA = 'ValueA';
String255 valueToFilterB = 'ValueB';
;
select count (RecId) from MyTable
where MyTable.Field like valueToFilterA
|| MyTable.Field like valueToFilterB;
If you don't know the number of values you should use query
object to add ranges dynamically:
如果您不知道值的数量,则应使用查询对象动态添加范围:
Query query = new Query();
QueryRun queryRun;
QueryBuildDataSource qbds;
QueryBuildRange queryRange;
container conValues;
;
qbds = query.addDataSource(tableNum(MyTable));
for (i = 1; i <= conlen(conValues); i++)
{
queryRange = qbds.addRange(fieldNum(MyTable, Field));
queryRange.value(SysQuery::valueLike(conPeek(conValues, i)));
}
queryRun = new QueryRun(query);
info(strFmt("Records count %1", SysQuery::countTotal(queryRun)));