(a) 或关系(假设两个值为value1和value2,类型为字符串):
View Code Qbr = qbds.addRange(fieldnum(InventTable,ItemId))Qbr.value(queryvalue(value1));Qbr.value(queryvalue(value2));或:Qbr = qbds.addRange(fieldnum(InventTable,ItemId))Qbr.value(queryvalue(value1,value2));或:Qbr = qbds.addRange(fieldnum(InventTable,ItemId))Qbr.value(strfmt(‘(( % 1 == “ % 2 ”) || ( % 1 == “ % 3 ”))’,fieldstr(InventTable,ItemId),queryvalue(value1),queryvalue(value2))
(b) 与关系(假设两个值为value1和value2,类型为字符串):
Qbr = qbds.addRange(fieldnum(InventTable,ItemId))Qbr.value(strfmt(‘(( % 1 == “ % 2 ”) && ( % 1 == “ % 3 ”)),fieldstr(InventTable,ItemId),queryvalue(value1),queryvalue(value2));
(c) 取值范围(value1<=value<=value2)
Qbr = qbds.addRange(fieldnum(InventTable,ItemId))Qbr.value(queryvalue(value1) + ’..’ + queryvalue(value2));或:Qbr = qbds.addRange(fieldnum(InventTable,ItemId))Qbr.value(strfmt(‘(( % 1 >= “ % 2 ”) && ( % 1 <= “ % 3 ”))’,fieldstr(InventTable,ItemId),queryvalue(value1),queryvalue(value2)); (value1 < value < value2)Qbr = qbds.addRange(fieldnum(InventTable,ItemId))Qbr.value(strfmt(‘(( % 1 > “ % 2 ”) && ( % 1 < “ % 3 ”))’,fieldstr(InventTable,ItemId),queryvalue(value1),queryvalue(value2));
需要注意的是在过滤date型数据时,表达式中不能使用’<=’或’>=’符号。
Date2strXpp(date)方法将一个date变量转换为可以在query.value中使用的字符串。Date 类型同样可以使用’>’,’<’或’>=’,’<=’.
Str queryExpr = ‘(‘ + Fieldid2name(tablenum(SalesLine),fieldnum(SalesLine,ShippingDateRequested)) + ‘ > ’ + date2strxpp(tmpDate) + ‘)’;Qbr = Qbds.addRange(fieldnum(SalesLine,ShippingDateRequested));Qbr.value(strfmt(‘( % 1 . % 2 < % 3 )’,tablestr(SalesLine),Fieldstr(SalesLine,ShippingDateRequested),Date2strxpp(tmpDate))); 或:Date paymentDateFrom,paymentDateTo;Qbr = qbds.addRange(fieldnum(SalesLine,ShippingDateRequested));Qbr.value(queryValue(paymentDateFrom) + ’..’);或:Qbr.value(queryValue(paymentDateFrom) + ’..’ + Queryvalue(paymentDateTo));或:Qbr.value(‘..’ + queryvalue(paymentDateTo));
在过滤数组型的字段时,可以使用方法fieldId2Ext(fieldId,tableIndex)来添加range,如:
Qbds = query.addDateSource(tablenum(CustTable));Qbr = qbds.addRange(fieldId2Ext(fieldnum(CustTable,Dimension), 1 ));Qbr.value(strfmt(‘ % 1 ’,dimension[ 1 ]));qbds.addRange(fieldId2Ext(fieldnum(CustTable,Dimension), 2 ));Qbr.value(strfmt(‘ % 1 ’,dimension[ 2 ]));qbds.addRange(fieldId2Ext(fieldnum(CustTable,Dimension), 3 ));Qbr.value(strfmt(‘ % 1 ’,dimension[ 3 ]));这里%1可以用双引号引起来,也可以不引起来。
在这两种格式下,需要注意一点:在表达是中需要用到:table.field样式,这里的table的名字指所添加的datasource的名字,如果你添加一个custTable表作为datasource,你将该datasource命名为custTable_1,那么,在你的表达是中就需要写成custTable_1.field。为了进一步说明这一点,上边第二个例子可以写成这样:
View Code queryExpr = ' (( ' + " CustTable_1 " + ' . ' + fieldid2name(tablenum(CustTable),fieldnum(CustTable,AccountNum)) + ' ==" ' + queryvalue( " 1101 " ) + ' ")&&( ' + " CustTable_1 " + ' . ' + fieldid2name(tablenum(CustTable),fieldnum(CustTable,Name)) + ' ==" ' + queryvalue( " Forest Wholesales " ) + ' ")) ' ;query = new Query(); qbds = query.addDataSource(tablenum(CustTable), ' CustTable_1 ' );qbr = qbds.addRange(fieldnum(CustTable,AccountNum));qbr.value(queryExpr);
query也可以根据条件排序,Group by或 Order by.
query.dataSourceTable(tablenum(CustTable)).orderMode(OrderMode::Order by)//或Group by
queryBuildDataSource.addSortRange(fieldNum(CustTable,AccountNum),SortMode::Descending);
query.addSelectionField(fieldnum(IWS_InventDimSumView,SumOfPhysicalInvent),SelectionField::Sum); //Sum or AVG
也可以用queryBuildDataSource.joinMode()来设置关联模式。
转载于:https://www.cnblogs.com/Kurodo/archive/2011/07/16/2108414.html