How to define filter criterion on database query in Sage X3

By | July 29, 2017

In Sage X3 latest versions, we are provided with new feature to define filter criterion on the database. This function defines a filtering condition on a database query. The condition is expressed in Sdata where syntax.

This function is only valid inside a Where clause of a database instruction (For, Filter, File, Link).

Syntax:

Where evaluesdata(EXPRESSION, VARIABLES, COLUMNS)

  • EXPRESSION is a filter expressed in SData where syntax.
  • VARIABLES is an array containing the variable names used in the filter.
  • COLUMNS is an array containing the database columns referenced by the variable names.

Example:

Local File MYTABLE [MYT] Local Char VARS(20)(1..2), COLS(20)(1..2)
VARS(1)=”city” : VARS(2)=”total”
COLS(1)=”[MYT]CITYNAME” : COLS(2)=”[MYT]AMOUNT”

# The condition
Filter [MYT] Where evalueSData(
& “(city in ‘London’,’Paris’) and (total between 1 and 10) ”
& , VARS, COLS)
# is equivalent to
Filter [MYT] Where find(CITYNAME,’London’,’Paris’) and (AMOUNT>=1 and AMOUNT<=100)

Here, the output data will contain city(either London or paris) and total amount between 1 to 100.

Comments:

This function only supports the following subset of the SData Query language:

  • String, numeric, date and datetime literals (for example, ‘Hello “World”‘,”I’m tired”, 3.14, @1959-05-29@, @2008-05-19T16:41:00Z@).
  • Parentheses
  • The following operators and functions:
Keyword Description Example
lt less than amount lt 5000
gt greather than amount gt 3000
le less or equal amount le 4500
ge greater or equal amount ge 7800
eq equal amount eq 3000
ne not equal amount ne 3000
between … and… between two values amount between 20 and 30
in contained in a list of values amount in (3,14,15,9,26)
like matches a string pattern name like ‘%PONT%’
and logical and amount ne 300 and amount ne 500
or logical or amount eq 300 or amount eq 500
abs absolute value abs(amount) eq 6
ascii ASCII code of first character ascii(countrycode) eq 32
char single char from ASCII code countrycode eq char(32)
div division amount div 2 eq 3
left(str,len) leftmost `len` characters from str; `str` if less than `len` characters left(name,3)=”Doe”
lower(str) converts str to lower case lower(name)=”doe”
upper(str) converts str to upper case lower(name)=”DOE”
mod modulus number mod 2 eq 0
mul multiplication amount mul 3 eq 15
not negation not (amount eq 3)
pow power amount pow 3 eq 125
right(str,len) rightmost `len` characters from `str`; `str` if less than `len` characters right(name,2)=’oe’
substring(str,index,len) substring starting at `start` and containing `len` characters; start is 1-based substring(name,4,5)=’ti’

About Us
Greytrix – a globally recognized Premier Sage Gold Development Partner is a one-stop solution provider for Sage ERP and Sage CRM needs. Being recognized and rewarded for multi-man years of experience, we bring complete end-to-end assistance for your technical consultations, product customizations, data migration, system integrations, third-party add-on development and implementation expertise.

Greytrix caters to a wide range of Sage Enterprise Management (Sage X3) offerings – a Sage Business Cloud Solution. Our unique GUMU™ integrations include Sage Enterprise Management (Sage X3) for Sage CRMSalesforce.com and Magento eCommerce along with Implementation and Technical Support worldwide for Sage Enterprise Management (Sage X3). Currently we are Sage Enterprise Management Implementation Partner in East Africa, Middles East, Australia, Asia. We also offer best-in-class Sage X3 customization and development services, integrated applications such as POS | WMS | Payment Gateway | Shipping System | Business Intelligence | eCommerce and have developed add-ons such as Catch – Weight  and Letter of Credit for Sage Enterprise Management to Sage business partners, end users and Sage PSG worldwide.

Greytrix is a recognized Sage Rockstar ISV Partner for GUMU™ Sage Enterprise Management – Sage CRM integration also listed on Sage Marketplace; GUMU™ integration for Sage Enterprise Management – Salesforce is a 5-star app listed on Salesforce AppExchange.

For more information on Sage X3 Integration and Services, please contact us at x3@greytrix.com. We will be glad to assist you.