Kinetic BAQDesignerUserGuide 2023.1
Kinetic BAQDesignerUserGuide 2023.1
Activity Query
Designer User Guide
Version 2023.1
Disclaimer
This document is for informational purposes only and is subject to change without notice. This
document and its contents, including the viewpoints, dates and functional content expressed herein
are believed to be accurate as of its date of publication. However, Epicor Software Corporation makes
no guarantee, representations or warranties with regard to the enclosed information and specifically
disclaims any applicable implied warranties, such as fitness for a particular purpose, merchantability,
satisfactory quality or reasonable skill and care. As each user of Epicor software is likely to be unique
in their requirements in the use of such software and their business processes, users of this document
are always advised to discuss the content of this document with their Epicor account manager. All
information contained herein is subject to change without notice and changes to this document since
printing and other important information about the software product are made or published in
release notes, and you are urged to obtain the current release notes for the software product. We
welcome user comments and reserve the right to revise this publication and/or make improvements
or changes to the products or programs described in this publication at any time, without notice.
The usage of any Epicor software shall be pursuant to an Epicor end user license agreement and the
performance of any consulting services by Epicor personnel shall be pursuant to Epicor's standard
services terms and conditions. Usage of the solution(s) described in this document with other Epicor
software or third party products may require the purchase of licenses for such other products. Where
any software is expressed to be compliant with local laws or requirements in this document, such
compliance is not a warranty and is based solely on Epicor's current understanding of such laws and
requirements. All laws and requirements are subject to varying interpretations as well as to change
and accordingly Epicor cannot guarantee that the software will be compliant and up to date with such
changes. All statements of platform and product compatibility in this document shall be considered
individually in relation to the products referred to in the relevant statement, i.e., where any Epicor
software is stated to be compatible with one product and also stated to be compatible with another
product, it should not be interpreted that such Epicor software is compatible with both of the
products running at the same time on the same platform or environment. Additionally platform or
product compatibility may require the application of Epicor or third-party updates, patches and/or
service packs and Epicor has no responsibility for compatibility issues which may be caused by
updates, patches and/or service packs released by third parties after the date of publication of this
document.
Epicor® is a registered trademark and/or trademark of Epicor Software Corporation in the United
States, certain other countries and/or the EU. All other trademarks mentioned are the property of
their respective owners.
All rights reserved. No part of this publication may be reproduced in any form without the prior
written consent of Epicor Software Corporation.
Table of Contents
3 March, 2023
Creating a BAQ Search 72
Selecting a BAQ Search 74
Setting Up Execution Settings 79
Adding Execution Settings 79
Editing Execution Settings 82
Reviewing Execution Settings 84
Using Query Parameters 91
Creating BAQ Parameters 91
Creating BAQ Parameters in the Query Designer 96
Avoiding BAQ Constant Names 97
Using Parameters 98
Using SubQueries 101
Adding SubQueries 101
Defining SubQueries 103
Selecting Consistent Columns 112
Moving Items Between SubQueries 114
Creating a New SubQuery 115
Moving Items to an Existing SubQuery 117
Managing SubQueries 119
Copying SubQueries 122
Entering an Advanced Group By Clause 125
What Are Advanced Group By Clauses? 125
Advanced Group By Operators 125
Displaying Results Through Advanced Group By Clauses 126
Creating the Query 126
Adding the Table 127
Selecting Display Fields 128
Entering the ROLLUP Advanced Group By Clause 130
Entering the CUBE Advanced Group By Clause 132
Entering the GROUPING SETS Advanced Group By Clause 134
Aggregating Data Using PIVOT and UNPIVOT 136
Aggregating Data Using a PIVOT 136
Aggregating Data Using an UNPIVOT 149
Create the Query 150
Add the Inner SubQuery 150
Create the UNPIVOT Expression 153
Testing a Query 160
Analyzing a Query 160
4 March, 2023
Testing a Query 160
Technical Details 162
Viewing Where Queries Are Used 163
5 March, 2023
Working with Business Activity Query (BAQ)
Designer
The Business Activity Query (BAQ) Designer continues to incorporate more features from
the Classic user interface. Most BAQ features are available in the Kinetic user interface.
However the following feature is only in the Classic version:
l Updatable BAQs
Full BAQ Designer capabilities are coming in a later release. If you need to create a query
with the above feature, please use the Classic version accessible from within the smart
client.
Use the BAQ Designer to create new database queries (BAQs) and copy or modify existing ones. You can
use BAQs as data sources for Dashboards, Searches, or BAQ Reports. The exporting capabilities makes
the queries available to view and edit in third party applications.
Leveraging this functionality does require some knowledge of database concepts such as
table relationships, records, and field types. This knowledge helps you create queries that
have good performance and display the results you want. You start by defining what
information you want to display in your BAQ. You then find which database tables contain
the appropriate columns which hold this data. Application tools can help you find this
database information.
6 March, 2023
Using Database Viewing Tools
Kinetic contains tools to help you locate database information you need before you start designing your
custom query. These tools also reduce issues with your BAQs, as you can leverage them to make sure
you reference correct fields and tables within your modified and personalized queries.
Field Help
Use the Field Help feature to display the technical details on a specific field within. You activate Field
using the Help and Support panel.
For more information see Using the Help and Support Panel in Kinetic Home Page.
7 March, 2023
Once enabled, you can click question marks next to fields to open a Field Help panel.
l Description - Displays the concise explanation for the field. This text explains the field’s purpose
and other useful information.
l Field Name - Displays the selected field.
l EpiBinding - Displays the name to use if you want to link to this field through a customization or
a code reference. This value uses the ViewName.FieldName format. ViewName is the name of the
view on the user interface; FieldName is the database column name.
l DB Field - Value contains the information you most likely need for your BAQ. It displays the table
name and the column name for the selected field. Typically, this value is identical to the
EpiBinding value and it displays the true database name for the field.
l Format - Defines the layout for the characters within the field. This value displays in either
schema or alphanumeric format; for example, X(30).
l Decimals - If the field is a Decimal type, the Decimals field displays how many decimal positions
are available within the field.
l Data Type - Defines the selected field’s main data definition. The type defines the data that
appears within the field; for example; string, number and boolean (True or False).
l Column Label - If the field is displayed on a grid, this field indicates the text that appears at the
top of the grid column.
l Like - The Like value for the selected column. This value links the column to another column on a
different, or foreign, table. These columns share a logical link and can be used to display the data
shared by these linked tables.
8 March, 2023
BAQ Table Details Tab
Use the Table Details tab in BAQ Designer to view the list of fields and their Data Type. The information
is displayed for each table you place on a canvas.
9 March, 2023
Creating a New Query
In this article, learn how to create a new business activity query (BAQ). You first define the query’s
identifier and description. You also indicate whether this query should be available to all users within
the company, available between multiple companies, and retrieve data across companies.
1. From the Kinetic menu, select Business Activity Query. It launches on a new page in your
browser.
2. In BAQ Studio Home Page, review the Query List drop down. The Regular BAQs option displays
by default.
If you will create an external query, select External BAQs from this list. You then
connect this query to an external datasource. For more information, review the
Creating an External Query help article.
5. The Author field displays the name of the current user logged into the system. Other users
cannot modify this query (BAQ).
As a BAQ creator, you can assign author rights to another user. To do so, press
Search to find and select a new author. The new author now has rights to edit
the BAQ.
10 March, 2023
6. The Owning Company displays the company where you are creating the current BAQ. You
cannot change this value; only the author within the Owning Company can modify this query.
7. You restrict access to a BAQ using Security codes. Configure these codes in Menu Security
Maintenance; they each limit access to user groups, specific users, and/or both. To assign a
Security ID, press Search to find and select a security code.
8. Select the Shared check box to indicate this query is available to all users. After you save the
query, all users in your company can use it through the available BAQ functions, such as Quick
Searches, BAQ info zones, BAQ reports, and dashboards.
These users will need various rights to use these features. System managers grant
these rights to user accounts in User Account Security Maintenance.
9. The All Companies check box controls whether the current BAQ is visible to all companies on the
same database server. When Kinetic uses multiple companies within a single database, the
system applies BAQ use and visibility regardless of multi-company direct configuration. For
companies hosted on different databases, this check box launches Service Bus processing to
synchronize BAQs across external companies. If the custom BAQ is created from a Company that
runs under a multi-tenant license, the definition is visible to all companies within the same
Tenancy as the Owning Company.
l Only users within the original company can update the BAQ definition, but users can
review and run it within other companies. To modify the BAQ definition in other
companies, create a copy of the BAQ within each company that needs to change it.
l Each query that has the All Companies property must have a unique BAQ ID across all
companies.
l When you create a BAQ visible across companies in Company A, and Company B uses a
local BAQ with the same ID, a warning message displays. The system informs the user that
in Company B, the local BAQ is used and the BAQ created in Company A will not be
available.
l Likewise, a warning message displays when you create a local BAQ in Company A, but in
Company B another BAQ has the same ID and is visible to all companies. They system
states that the local BAQ takes precedence over the All Companies BAQ. The same warning
displays when you import a local BAQ that has the same ID as another BAQ set for all
companies.
l When a naming conflict occurs, the local BAQ always take precedence over the BAQ visible
to all companies.
To see which companies outside the current company references a BAQ, use the
Where Used option. Select this option from the Overflow menu .
11 March, 2023
10. The System BAQ option indicates whether the current BAQ installed with the Kinetic system. You
cannot change a system query, but they are a great starting point for creating your own queries.
Do this by copying and renaming it, modifying this copied query as you need. To do so, from the
11. The Cross-company check box controls if the BAQ brings back results across multiple
companies. To design a cross-company BAQ, a user must have Allow creation of cross-company
BAQ. A system manager assigns these rights in User Account Security Maintenance.
12. After you finish entering the main BAQ information, click Save .
12 March, 2023
Using the Query Designer
Use the Query Designer to create a Business Activity Query (BAQ). Use the designer to set up everything
from basic queries with a single table to complex queries that include multiple subqueries of different
types, joins, or query parameters.
Adding Tables
Use the Query Designer to first add the database tables that will pull data into your custom query.
l When you create a new query (BAQ), the first subquery the designer creates is
SubQuery1 by default. This is a TopLevel subquery type. Each BAQ must have only
one TopLevel subquery.
l Because all queries are subqueries of the database, the BAQ designer calls all its
levels subqueries, including the TopLevel subquery.
l You can add multiple Inner subqueries to a BAQ; these are embedded within the
WHERE clause of the TopLevel subquery.
3. Start by adding a table. Use the Search box to locate the table.
13 March, 2023
4. Either double-click it or select the table and drag it to the design canvas.
5. If you wish to remove a table, select the table and click the Trash button.
6. You can add multiple tables at once. To do so, search for and select tables you want to add and
drag them to the design canvas.
7. Use the Connected Tables panel to display tables that have relations with the table you select
on the canvas. The panel displays Extension Tables when the connection with the selected table
14 March, 2023
is defined in Extension Table settings.
8. When you place two tables on the canvas, and a relation between tables exists (described in the
dictionary), the Query Designer automatically adds the relation. The relation is shown by a line
that links the tables which indicates the JOIN clause. You can also manually create table relations
or replace existing relationships.
9. Each query (BAQ) can have multiple subqueries. Much like layers within a cake, you can link
subqueries to generate results specific for your industry or business area. Each subquery has a
different type. When InnerSubQuery or CTE type subqueries are in the current query (BAQ), you
can drag these subqueries on the canvas to also use the JOIN clause to link the subquery to
tables or other subqueries. This link the pulls data from the subquery into the current subquery.
15 March, 2023
For more information, see Using SubQueries.
1. Add tables to the design canvas. The layout buttons display in the upper right corner of the
design canvas.
2. Select the Fit to Screen button to display all the tables within the visible design canvas.
16 March, 2023
4. Select Zoom Out to see more of the design canvas.
5. Select Restore to Scale to return the design canvas layout to its original size.
6. Select Layout Automatically to evenly space the tables around the design canvas.
The correct order of tables is crucial for retrieving the expected BAQ results. The first table
listed in the FROM clause of the resulting SQL statement is explicitly set on this tab. The
order of these other tables is based on table relations.
1. The current position of each table is represented by a number. To change the order of the tables,
select a table and use the Up or Down arrow on the toolbar to move the selected table one
position up or down. Use these arrows as you need to define the new table order.
17 March, 2023
2. In this example OrderHed table is first on the list, so the resulting syntax shows this table order:
select *
3. By making the OrderDtl table first on the list, the resulting syntax changes to this table order:
select *
The correct order of tables is a crucial step in retrieving the expected BAQ results.
l Matching rows from {left joined table} and {right joined table} - This is the default join; the
subquery only selects rows that satisfy the join criteria from both joined tables. The query results
from this join type include all the records where the table relations values in both tables match. A
record in one table only displays if a corresponding record in the joined table links to it.
18 March, 2023
The join between the Customer (table1) and the OrderHed (table2) creates a view
that displays customers and sales orders. In this example, the view only includes
customers who have placed an order. Records for any customers who have not
placed an order are excluded from the query results.
l All Rows from {left joined table} -The subquery selects rows that satisfy join criteria from both
joined tables as well as all rows from the left joined table -- including its Null rows. The subquery
displays everything from table1 and linked rows from table2.
Use the All Rows from {left joined table} join to view all customers (table1) and the
sales orders (table2) for these customers. This query also displays every customer
who has not placed an order. If a customer did not place an order, fields that
display the order information are blank.
l All Rows from {right joined table} - The subquery selects rows that satisfy join criteria from
both joined tables as well as all rows from the right joined table -- including its Null rows. The
subquery displays everything from table2 and linked rows from table1.
Use the All Rows from {right joined table} join to find each employee (table1) and
his or her department (table2), but still show departments that have no employees.
19 March, 2023
l All Rows from {left joined table} and {right joined table} - The subquery selects rows that
satisfy join criteria from both joined tables as well as all remaining rows both from the left joined
table and the right joined table along with Null rows. In SQL, this type of join combines the
results of both left and right outer joins and returns all (matched or unmatched) rows from the
tables on both sides of the join clause.
Use the All Rows from {left joined table} and {right joined table} to show all the
Customers (table1) and all the sales orders (table2) in the database.
1. When you place two tables on the canvas and they have a relationship described in the
dictionary, a line displays that indicates the JOIN clause. The Query Designer supports
automatically creating JOIN clauses between standard Kinetic tables, Kinetic tables and
Extension tables, and Extension tables. In this example, QuoteHed and Customer tables are on
the canvas.
20 March, 2023
l When the relation is between two standard tables, the default relationship uses the Matching
rows from {left joined table} and {right joined table} join type, which means that data from
the first table only displays if it links to data within the second table. The query output from a
Matching rows join includes all the records in which the table relation values in both tables are
an exact match. Records from either table that do not have a match in the other table are not
included in the query results.
l When relation is between standard and extension tables, the default relationship uses the All
Rows from {left joined table} join type, which means that join criteria includes all rows from the
standard table and only includes matching rows from the extension table. The designer selects
data between the two tables using the Extension Table settings.
l When relation is between two extension tables, the default relationship includes all rows from
the parent table and only matching rows from the child table.
2. If a predefined relationship exists between the selected tables, you can use the Dictionary panel
to view and select one of the predefined join types. When you place two tables on the design
canvas, and the relationship between these tables is described in the dictionary, the SubQuery
Designer automatically uses this default join type. As you place a subsequent table on the design
canvas, the SubQuery Designer checks the relation with the previous table within the table order.
It does not check relations to all possible tables within the query. The Dictionary panel also
displays number of predefined dictionary relations.
21 March, 2023
3. The Dictionary panel lists all relations with their fields. The result relation join type expression
displays in the Expression field. You can select one of the relations and press Replace In Query.
Fields from the Dictionary will replace fields used in the current BAQ relation.
22 March, 2023
4. In this example, the designer modified the default relation between the tables to use
QuoteHed.ShipToCustNum instead of QuoteHed.CustNum.
1. In this example, assume you want to connect the Terms and APInvHed table. Create a join by
dragging and dropping between them. Make sure the tables connect with the line.
23 March, 2023
2. You can use the Table Details tab to see if the tables share any common fields you could use to
create a table relation. In this example, the Company and TermsCode fields are in both tables.
3. To define the table relation, select the line between the tables. With the Table Relations tab
selected, press New.
4. Create a join between the first and second table. In this example, you select the Company and
TermsCode columns to join the tables.
24 March, 2023
5. You have the following options to create a relation:
l Create a simple join between table fields using the field1 = field2 pattern.
l Construct an advanced expression, for example, using functions or operations different
from = (equals). There is no list of predefined operators, you can enter a custom
expression.
l When the tables you add are not joined by any field, the designer automatically selects the
CROSS JOIN (Cartesian join). This join returns all records where each row from the first
table is combined with each row from the second table.
l When you apply criteria on the FIRST table in the query, these criteria go to the WHERE part of
the resulting SQL statement.
l When you apply criteria on a table other than the first query table that is connected to the
previous table with a JOIN clause, the BAQ designer applies these criteria to the JOIN clause in
the ON condition within the resulting SQL statement.
l Consider leaving the query criteria open. You then have more flexibility within the query, as you
can always add a filter to the query results within a dashboard or a BAQ report.
To add table criteria:
25 March, 2023
1. Select a table on the canvas for which you want to filter the data.
2. Select New .
3. In this example, you add a filter on the OrderHed table to only display open orders. From the
Field Name, select OpenOrder.
4. The Operation field defines how the system evaluates the selected field against the Filter Value.
In this example, accept the default = (equals) option. The Filter Value can be an alphanumeric
value.
Operator Description
= Equals
26 March, 2023
Operator Description
BEGINS Returns data that starts with the same characters. Although this operator is less
efficient compared to the Greater than or Equal sign (>=), you can use this value
to pull in a series of records that start with the same set of alphanumeric
characters.
MATCHES Returns data that is exactly the same as the character string. Although this
operator is less efficient compared to the Equal sign (=), you can use asterisk
wildcards to pull in data. For example: MATCHES '*owe*' finds both owe and
powerful. With MATCHES, you can use no asterisks, a left asterisk, a right asterisk
or both asterisks.
ISNULL Returns fields that have an unknown, or "NULL" value. Typical uses cases include:
l Find rows with the EMPTY string value, use comparison with an empty
constant. The example of an empty constant looks as follows:
l Find rows with unassigned fields. This operation may be useful in external
queries which execute against non-Epicor databases.
IN Indicates this value is used with either a list of constant values or a BAQ item list
parameter, or a field from an inner SubQuery.
CONTAINS Returns data when the selected character field has data which is present within
the defined Filter Value.
27 March, 2023
Operator Description
EXISTS The EXISTS condition is considered to be met if the subquery returns at least one
row. This condition can be used in any valid SELECT SQL statement. The syntax
for the EXISTS condition looks as follows:
SELECT columns
FROM tables
WHERE EXISTS ( subquery )
With this operator selected, the only Filter Value available is "a row in specified
subquery".
5. Now, specify the Filter Value. First, select an option from the drop-down list. In this example,
select the specified constant option. Click on specified to invoke the Specify Value sliding
panel. For Value, enter False and press OK.
28 March, 2023
Filter Description
specified Use this option to filter the data using a field from a table included in the query.
table field l From the Table Name drop-down list, select the table that contains the fields
value you want to filter against. All the tables available in your current subquery
display.
l The available fields display in the fields section. Select the field you want to use
in the criterion and press OK.
specified Use this option to filter the data against a specific value you define.
constant l You can enter any text value you need. Depending on what you enter, some
values may or may not be case sensitive.
l Enter the value you want to filter against and press OK.
29 March, 2023
Filter Description
specified Use this option to filter the data against a specific expression you create. You
expression can use this filter to build complex expressions calculate when the system
applies the criterion to the query.
l The Specify Expression panel has a free form text field. You can use this field to
directly enter the expression.
l You can also use the Data and Functions Nav Trees to select items for the
expression. The Nav Trees on Specify Expression panel are similar to the
Calculated Field Editor panel. Learn more about this panel by reviewing the
Creating Calculated Fields help article.
l Enter a valid SQL Expression and press OK.
30 March, 2023
Filter Description
specified Use this option to filter the data using an alternative parameter value(s)
parameter defined for a BAQ. You can also use parameters to display customized method
arguments for use in Business Process Management (BPM) directives.
l In the Select Parameter window, specify the parameter and press OK.
For example, you create a parameter listing part numbers. When the query
runs, the Define Parameter window displays, asking a user to select a part. The
selected part value is dynamically used in the specified condition. To create
parameters, use the Query Parameters option found on the BAQ Home Page
overflow menu.
For more information, see Using Query Parameters.
31 March, 2023
Filter Description
BAQ special Use this option to filter against a specific constant, like CurrentCompany, Cur-
constant rentEmployeeID, First Day of the Month, Fiscal Period, and so on. The query
pulls data based on the BAQ constant you select. To review the complete last of
BAQ constants, review the Calculated Fields - Functions, Operators and BAQ
Constants section in the Creating Calculated Fields help article.
l From the list, select a BAQ constant and press OK.
32 March, 2023
Filter Description
Current Use this option to filter query results by date intervals: days, weeks, months,
date + spe- and years. The result is always evaluated against the current company date
cified inter- (TODAY). You can enter a positive or negative value; the value is then added or
val subtracted from the current company date to calculate a different date.
l Use the controls to define the next execution date.
l The current date is retrieved from Constants.Today. This constant allows to set
the date according to the time zone based on the company location.
selected Use this option to filter the data using values of a subquery field(s) you define.
value(s) of l Press selected to toggle between:
field from
l ALL - the condition evaluates against all values returned from a subquery.
specified
subquery
l ANY - comparison with at least one value returned from a subquery.
l Press specified to invoke the Select SubQuery panel. From the drop-down,
select a subquery. Note only InnerSubQuery and CTE subqueries display on this
list.
l Select a Field against which you want to filter data.
33 March, 2023
Filter Description
Operation For certain operations, only specific filters are available for use.
specific fil- l IN operation:
ters
l specified constants list - Use this filter to specify the list of constants.
l specified list parameter - Use this filter to select an Item List parameter
you want to use in the query execution. This parameter contains a list of
values supplied during query execution.
l field from specified subquery - Use this option to filter the data using a
subquery field(s) you define. You can select fields from InnerSubQuery or
CTE subqueries.
l EXISTS operation:
l a row in specified subquery - Use this option to filter the data using a
subquery you define. You can select InnerSubQuery or CTE subqueries.
This operator only checks that a row is returned.
l CONTAINS operation:
l specified contains expression - Use this filter to launch the Specify
Expression window. Use this form to create an expression compatible
with the CONTAINS predicate in SQL. Supported terms: AND (&), OR (|),
wildcard (*), parentheses (()). Full-text indexed column is required.
34 March, 2023
7. When you finish, press Save.
8. Review the Query Phrase to verify the criterion is included as part of the resulting SQL syntax
WHERE clause.
l In the resulting SQL statement, the subquery criterion displays in the WHERE part of
the subquery.
l When you select the Having check box to indicate the subquery should meet
specified conditions, the criterion displays within the subquery's HAVING part of the
resulting SQL statement.
1. First, select a subquery where you want to apply a filter. In this example, the BAQ uses two
subqueries joined using the UNION operator to return customer Quotes and Orders. We will
create a filter on each SubQuery to display data for a particular customer.
35 March, 2023
2. Go to SubQuery Criteria tab and press New .
3. A new row displays in the SubQuery Criteria grid; enter the options you need for this filter. In
this example a criterion displays to return quotes for the customer Addison.
Entering a condition for the subquery is similar to entering Table Criteria. For a subquery,
first use the Alias field to select a subquery table or a predefined Calculated table name,
when referring to calculated fields. In this example, the Customer table is selected.
36 March, 2023
4. Create a condition by selecting the subquery Field Name, Operation and Filtering Value.
For a complete list of Operations and Filtering options, see Specifying table criteria.
5. When you select the Having check box, the SQL statement returns rows where aggregate values
meet the specified conditions. Typically you use this field with the calculated field editor. In this
example, we keep this option clear.
6. Similarly, we enter the criteria for the second SubQuery2. In this example, we limit the BAQ
results to only retrieve orders for the customer Dalton.
37 March, 2023
8. The following is an example of a Query Phrase that has filtering applied on both subqueries.
38 March, 2023
Selecting Display Fields
In this article, learn how to select the fields that display on your query, modify how these how these
fields display, change their column order, and remove them from display. You can also create
calculated fields, add and edit field attributes, and create advanced group by expressions.
2. If multiple tables are used in a SubQuery, select a table from the Available Tables list.
3. The columns appear that are available within the table. You can search for fields or sort columns
by Name, Data Type, and Description.
39 March, 2023
4. Select the fields you want to display.
5. Click the Right Arrow button to move the selected column(s) into the Display Fields(s) list.
1. Change the field name by entering a value in the Label field. This field displays the default field
name, but you can change the name. The name you enter displays on the column header within
the BAQ results grid.
2. To change the field's format mask, modify the value in the Format field. Use these options in
various combinations to display the results in the format you want. Several single character
40 March, 2023
format options are available:
l X - Any Character
l N - Number or Letter
l A - Letter Only
l ! - Lower Case Letter
l 9 - Number Only
l > - Suppress Zeros
For example:
l X(8)
l ->>>,>>>,>>9.9999
3. To group query results by specific column, select the Group By check box.
When selected, this field is listed in the Group By SQL clause as well as in the Select
clause. The Group By statement is often used in conjunction with aggregate queries
utilizing aggregate functions, such as AVG, SUM, or COUNT.
1. To move a field or multiple fields up in the column order, select a field(s) and use the Up Arrow
button.
41 March, 2023
2. To move a field or multiple fields up in the order, select a field(s) and click the Move to Top
button.
3. To move a field or multiple fields down in the order, select a field(s) and click the Down Arrow
button.
4. To move a field or multiple fields down in the order, select a field(s) and click the Move to
Bottom button.
42 March, 2023
Searching for Fields
If you need to find a specific field, use the grid filter options.
2. The grid filter row displays. Enter a value in one of the columns. For example, in the Label
column, enter order.
3. Click the Funnel button on the column. Select a filter option, such as Contains, Starts with,
Ends with, and so on.
The Display Fields grid only shows the fields that match your filter parameters.
Removing Fields
You can also remove fields from the BAQ results grid.
43 March, 2023
2. Click the Remove fields button.
2. Select the Calculated fields editor to create a field that generates results through a
calculated expression you define. To learn more, review the Creating Calculated Fields help
44 March, 2023
article.
3. Each field has a series of attributes you can use for Advanced Unit of Measure, Configurator,
and other functions. To learn about creating and editing them, review the Defining Field
Attributes help article.
4. An Advanced Group By clause groups the BAQ results using an expression, generating
results the shows more details about the data. For example, use the GROUPING SETS function to
group records together by sets of multiple values. Read the Entering an Advanced Group By
Clause help article for more details.
45 March, 2023
Creating Calculated Fields
Create user-defined columns that calculate a value using selected fields within the query. You can then
see additional information specific to your industry or business area. You build these fields using the
Calculated Field Editor panel. This panel contains lists of fields, functions, and operators. These
default items display in a Nav Tree where you can find the item you need. You can also directly enter
the expression in the Editor field.
46 March, 2023
5. The Calculated Fields panel slides on.
47 March, 2023
Creating a Calculated Field
Add the calculated field to the grid.
2. In the Field Name field, enter the name of the field for which you create the calculation. In this
example, enter BurdenHrs.
You can create calculated fields that have the same name in different queries, but you
cannot create two identical calculated fields within the same query. When you copy a
subquery that contains a calculated field, you will enter an alias name for the field.
48 March, 2023
3. Enter the Data Type this calculated field generates, such as decimal. Available data types
include:
l nvarchar (alphanumeric)
l int (integer)
l decimal
l date
l datetime
l bit (Boolean Y/N)
4. The Format field automatically displays the data format for this calculated field. In this example,
->>,>>>,>>9. If you need, change this value.
5. Enter the Label you want to display above this calculated field’s column header in the BAQ grid.
In this example, enter Burden Hours.
6. Optionally, enter a Description.
49 March, 2023
l BAQ Constants - Standard values from the system, such as CompanyName, CurrentTime,
DayOfWeek, and so on.
For a complete list of these options, see the Calculated fields - Functions,
Operators and BAQ Constants section.
3. Expand the node that has the function you want, such as Aggregate.
4. Select the function, such as Sum(x). Either double-click or drag and drop it onto your calculation
within the Editor field. The selected function displays in the editor.
5. Use the Data tab to search for and place a specific field within the calculation.
50 March, 2023
6. Expand the nodes on the Data Nav Tree to pull data from:
l Display Fields - Select any of the current Display Fields and Calculated Fields in the
current subquery.
l Available Tables - Pull in any fields contained within the tables you have included with
the current subquery.
l Parameters - If you have created parameters for the query, these options display under
the Parameters node. Parameters pull in multiple values that you can then use within your
calculation. For more information, see Using Query Parameters.
You cannot create a calculated field with a parameter that uses the Skip
condition if empty property. These parameters do not display on the list of
available parameters.
l Be sure to use the appropriate SQL syntax within the Editor pane.
l The Editor supports intelligent code editing, which includes invoking member
lists. To invoke a list of columns for a table, enter the name of the table
followed by a dot (.) and press Ctrl + Space. Select the column you need, it
will be added to the table name. For example, ABCCode.Company.
7. Expand the node that has the data you want, like the Available tables node.
51 March, 2023
8. Select the column you want in the expression, such as BurdenHrs.
9. When you complete the calculation, click Check Syntax to verify the calculation logic is valid.
52 March, 2023
Functions, Operators and BAQ Constants
Review the list of supported Functions, Operators and BAQ Constants you can use to build calculated
fields.
Functions
Users are not limited to the functions from the Nav Tree. You can place any function
supported by the SQL Server your system uses within an expression. For External BAQ
functionality, use functions supported in the database server where the external BAQ runs.
l Aggregate - aggregate functions perform a calculation on a set of values and return a single
value. Aggregate functions are frequently used with the GROUP BY clause of the SELECT
statement.
Function Description
Avg(x) avg(expression)
Calculates the average of all values within the numeric database field.
Count(x) count(expression)
Counts the number of times the database field was counted.
Max(x) max(expression)
Calculates the maximum of all of the values of the numeric database field.
Min(x) min(expression)
Calculates the minimum of all of the values of the numeric database field.
Sum(x) sum(expression)
Calculates the total of all the values of the numeric database field.
l Math - mathematical functions execute mathematical operations usually based on input values
that are provided as arguments, and return a numeric value as the result of the operation.
Function Description
Abs(x) abs(expression)
Returns the absolute value of a numeric expression.
Sqrt(x) sqrt(expression)
Returns the square root value of a decimal expression.
53 March, 2023
Function Description
Log(x) Log(expression)
Calculates the natural (e) logarithm of a decimal expression.
Log10(x) Log10(expression)
Calculates the base-10 logarithm of a decimal expression.
ASCII(x) ASCII(expression)
Converts a character expression representing a single character into the
corresponding ASCII value, returned as an integer.
Char(x) Char(expression)
Converts an ASCII integer code to its corresponding character value.
Len(x) Len(expression)
Returns the number of characters in an expression
Left-Trim(x) ltrim(expression)
Removes leading white space from a string expression.
Trim(x) ltrim(rtrim(expression))
Removes leading and trailing white space from a string expression.
Right-Trim trim(expression)
(x) Removes trailing white space from a string expression.
54 March, 2023
Function Description
Upper(x) upper(expression)
Converts any lowercase characters in a string expression to upper-case
characters.
lower(x) lower(expression )
Converts any upper-case characters in a string expression to lowercase
characters.
55 March, 2023
l Conversion - conversion functions transform an expression of one data type to another
Function Description
l Ranges - functions in this category return the position, string entry, or number of elements from
the list, based on the expression.
Function Description
56 March, 2023
Function Description
Num- [Ice].num_entries(list)
entries(x) Returns the number of elements in a list of character strings as an integer value.
l Financial - functions in this category return either the fiscal year or fiscal period for the supplied
date based on the fiscal calendar.
Function Description
For more information on converting one data type to another, for example when
converting date and time formats, see CAST and CONVERT (Transact-SQL).
Operators
An operator is a mathematical expression either used with a single function or used to process two or
more functions.
Editor
Section Tree View Expression
View
57 March, 2023
Editor
Section Tree View Expression
View
58 March, 2023
Editor
Section Tree View Expression
View
else
end
Other Comment /* */ Comment characters.
Allows adding explanatory text to a procedure
between the /* and */ characters.
Other Begins Begins Begins operator.
Tests a character expression to see if that expres-
sion begins with a second character expression.
Other Matches “* *” Matches operator.
Compares a character expression to a pattern and
evaluates to TRUE if the expression satisfies the
pattern criteria.
BAQ Constants
The following table displays the BAQ constants you can use within the Calculated Field Editor.
59 March, 2023
l Anytime the server code resolves Today or Now the method returns the value based
on the company time zone setting. If not set, it will use the app server time zone.
l When a BAQ runs, Today and other dependent constants, as well as the current
date value for current date-based condition, are calculated one time per query run,
and their values are based on the company time zone of the company from which
the BAQ is executed. For a Cross-Company BAQ, it means the value of Today and
dependent constants is calculated based on company time zone of user’s current
company; it is not recalculated for each company from which the data is retrieved
by Cross-Company BAQ.
CompanyName The Company Name of the company the user is logged into.
CountryCode The Country Code of the company the user is logged into.
CountryGroupCode The Country of Origin Code of the company the user is logged into.
CurComp The Company ID of the company the user is logged into.
Note: This constant is used for compatibility with queries written
in Epicor 9 after they were migrated or imported into Epicor ERP
Version 10. When building a new BAQ, use the CurrentCompany
constant.
CurCompName The Company Name of the company the user is logged into.
Note: This constant is used for compatibility with queries written
in Epicor 9 after they were migrated or imported into Epicor ERP
Version 10. When building a new BAQ, use the Cur-
rentCompanyName constant.
CurLangID The language ID of the language being used in the Main Menu of
the current session.
Note: This constant is used for compatibility with queries written
in Epicor 9 after they were migrated or imported into Epicor ERP
Version 10. When building a new BAQ, use the CurrentLanguageID
constant.
CurrentCompany The Company ID of the company the user is logged into.
CurrentCompanyName The Company Name of the company the user is logged into.
CurrentEmployeeID The Employee ID linked to the user of the current session.
60 March, 2023
BAQ Constant Descriptio
CurrentLanguageID The language ID of the language being used in the Main Menu of
the current session.
CurrentPlant The Plant ID of the company the user is logged into.
CurrentTime The current system time. Returns seconds elapsed since midnight.
CurrentUserID The User ID of the user of the current session.
Day The day of month of the Current Date.
DayOfWeek Returns the current day number of the current week.
DefUM The default Unit of Measure of the current site.
Note: This constant is used for compatibility with queries written
in Epicor 9 after they were migrated or imported into Epicor ERP
Version 10. When building a new BAQ, use the DefaultUM constant.
DefaultUM The default Unit of Measure of the current site.
DesignMode Indicates the special developer mode for Epicor developers is
used.
EmployeeID The employee id linked to the user of the current session.
FirstDayOfMonth The first day of the current month of the Current Date.
FirstDayOfNextMonth The first day of the next month of the Current Date.
FirstDayOfNextWeek The first day of the next week of the Current Date.
FirstDayOfPrevMonth The first day of the previous month of the Current Date.
FirstDayOfPrevWeek The first day of the previous week of the Current Date.
FirstDayOfWeek The first day of this week of the Current Date.
GlobalSecurityManager The current session user is a Global Company Security Manager.
LanguageID The language ID of the language being used in the Main Menu of
the current session.
Note: This constant is used for compatibility with queries written
in Epicor 9 after they were migrated or imported into Epicor ERP
Version 10. When building a new BAQ, use the CurrentLanguageID
constant.
61 March, 2023
BAQ Constant Descriptio
62 March, 2023
BAQ Constant Descriptio
63 March, 2023
Defining Field Attributes
Use the Field Attributes Panel to add, edit or remove attributes of the fields that display on your query.
Each database field has a set of properties such as format or label. Using the Field Attributes Panel, you
can modify the existing properties and create custom ones for the current BAQ. When the BAQ runs, it
uses the field attributes you define.
This feature set is similar to Extended Property Maintenance. Use this application to
modify the properties of fields in an application. Use the Field Attributes panel to add or
modify properties on the fields in your query.
64 March, 2023
4. The Display Fields drop-down list contains all the fields you selected to display on the query.
Select a field from the list.
65 March, 2023
Attribute Name displays the field attribute's name. When you create a custom attribute, you can
either select one of the predefined attribute types from the drop-down list, or, you can enter a
name of your choice as needed. Attribute names are not case sensitive.
Is Overridden check box is visual indicator if the field property is in it's default state or if it was
created or modified in any way.
66 March, 2023
5. Select New to add new attributes.
6. You can edit Attribute Name directly in that grid or modify them in the Field Attributes panel.
When you change database value of an attribute, the Is Overridden check box is selected
automatically.
Use the Reset Field Attributes Cache action to immediately remove the server-side cache that stores
system Field Attributes data and apply the changes you made to the field attributes in the query. When
the query runs, it uses these modified field attributes.
67 March, 2023
2. The system resets the field attributes.
Now when you run this query, it uses the attributes you defined on the Field
Attributes panel.
68 March, 2023
Defining the Sort Order
Use the Sort Order feature to define how the query results display when the query (BAQ) runs. You can
sort your data through any combination of columns. You can also select whether the data displays in
ascending or descending order.
If your query contains two or more subqueries, you can only select fields for the sort order
on the TopLevel subquery. If you define the sort order on a different subquery, you will
receive an error and the query does not run.
69 March, 2023
5. Select a column from the Available Fields grid that will sort the data and press the Right Arrow
button or drag and drop it. The selected field display in the Sort By grid.
6. Continue to add more fields to further define how the records sort.
7. If you need, use the Up and Down Arrow buttons to change the sorting order.
8. To control if data should sort in ascending or descending order, select the Sort by ascending
check box. You can either accept the default value of true (selected), or clear the Sort By
ascending check box to set the field to descending order.
9. Test the sorting results. Select the Run Query button.
70 March, 2023
10. Analyze and Test the query.
11. The query results display in the sort order you selected. The records sort in ascending order by
Warehouse, by Part, and then by Bin.
71 March, 2023
Defining BAQ Searches
Make your custom query available for searching in multiple applications by using the BAQ Search panel.
You select columns in your query that link to columns in other tables. When users launch a search panel
that links to these columns, your query displays as a BAQ Search option.
BAQ searches create this link by using the LIKE property. When two columns share a LIKE property, the
BAQ search can pull in records for display within the current application. For example, you create a
custom BAQ for the Part table. You select the Part_PartNum column as the first column in the BAQ
search. Any search panels that have columns that share the LIKE property with the Part_PartNum
column will include your custom query as a BAQ Search option.
You cannot use system queries for BAQ search options. If you want to add a system query,
copy this query and select this copied query for your BAQ search.
2. Select the Shared check box. Only shared queries will display for other users on the BAQ Search
panel.
72 March, 2023
3. Go to the Overflow menu and select BAQ Search.
4. The BAQ Search panel displays. The columns you selected for display in your BAQ appear in the
Available "Like" Columns list.
5. Select the check box next to each column you want to use in the BAQ Search.
7. Your selected columns display in the BAQ Search "Like" Columns grid.
73 March, 2023
The sequence in which you select columns for display is important. When users run
the query, the system uses the first column that shares the same LIKE property as
the search field LIKE property. This can cause unexpected search results. For
example, if the search field is Part_PartNum and the first column with a LIKE
property in the BAQ search sequence is the GlbPart_GlbPartNum column, the BAQ
search uses the Global Part (GlbPartNum) column to pull search results. If the
Global Part LIKE column has no values, the BAQ search will return records without
values in this column.
8. You can remove columns from this grid. Select the check box next to the column.
74 March, 2023
2. Go to the Landing Page. Click the Search icon in the Customer field.
3. The Search panel displays. Click the Search Type drop-down list and select BAQ.
4. The Search panel displays the BAQ Search options. Click the Search Id drop-down list and select
your custom query, such as InvoiceQuery.
75 March, 2023
5. The Search Results grid displays the data from your custom query.
76 March, 2023
6. You can keep this BAQ Search as a personal search option. Select the Save Search button.
7. The Personalize Search panel displays. Enter a Search Name that helps you identify the search
option.
8. If you want to make the BAQ search the first option that displays in the Search panel, select the
Default Search check box.
77 March, 2023
10. The BAQ Search now becomes a Personal search option.
78 March, 2023
Setting Up Execution Settings
Modify BAQ execution parameters to change how the query runs and displays its results set. You can set
up paging parameters to indicate how the BAQ should get a sub-selection of data from a record set,
specify the longest time in which the query can run, or supply SQL statements, clauses, and keywords
to modify the resulting SQL syntax.
2. Select Use Primary Database to run the query against your main database. If this check box is
clear, the query runs against a read-only database.
79 March, 2023
When you activate the Always On availability groups feature on the SQL server,
BAQs can run against a read-only database. If your company does not have a read-
only copy of the main database, all standard BAQs run against the main database
regardless of whether you select the Use Primary Database check box.
If the query is updatable, the system automatically selects the Use Primary
Database check box. Updatable queries must access and update current data.
80 March, 2023
4. Start typing in the blank field to see the list of execution settings. Select a setting. Read the
Reviewing Execution Settings section below for details on each setting.
81 March, 2023
8. The setting displays on the Query Executing Settings grid.
82 March, 2023
2. Select the link for the execution setting.
83 March, 2023
3. The options for the selected setting display. Enter the changes you need.
Setting Description
GenerateExecution Shows you the query execution plan returned by the query results. The
Plan query uses this plan in the Get Query Execution Plan action.
GroupBy Setting name for a comma-delimited field list by which you sort query
results. Make sure you reference fields using the BAQ Alias notation in the
following format: TableName_FieldName
For example: ABCCode_Company
Having Setting name for condition that appears in the HAVING clause in addition to
query settings. Make sure you reference fields using the BAQ Alias notation
in the following format: TableName_FieldName
84 March, 2023
Setting Description
NeedTotal Specifies if the total number of rows in the query is received (without
paging). If this flag is set to True, the ExecutionInfo table in the result
dataset that returns contains the total number of rows.
You typically should use False for this setting to reduce server
load.
OrderBy Setting name for comma-delimited field list by which you want sort the
query result. Optional direction can be specified in SQL notation (ASC/DESC).
Make sure you reference fields using the BAQ Alias notation in the following
format: TableName_FieldName
PageCount Specifies how many pages of data the query returns. By default, PageCount
is set to 1 which means that the returned data displays on a single page. You
can set this value to any positive number greater than 0.
Paging Method Specifies the method used to retrieve data from the datasource. Available
values include:
l Auto - The default paging method. When selected, the query tries to
automatically select the most appropriate paging method, supported
by the BAQ definition and the database engine.
l Simple - When a query runs, its results return through DbDataReader,
but only the required page loads into the result table. This paging
should run for any database, so use it when the Auto method does not
work.
PageNum Specifies the page number user wants to get. The default value is 1.
Be aware that if you set this value to 10 (for example), but the BAQ only
returns 3 pages of data, the query displays an empty result set.
85 March, 2023
Setting Description
PageSize Specifies how many rows per page the query retrieves in the result set.
Available values include:
86 March, 2023
Setting Description
Persistent in Query Select the Persistent in Query check box so the query uses all execution
settings each time the BAQ runs. If a BAQ runs a subsequent execution
setting and an original setting is still active, the first setting has higher
priority.
If the Persistent in Query check box is clear, the settings only run once
during the current BAQ session. You must close and relaunch the BAQ before
the settings run again.
87 March, 2023
Setting Description
QueryOption Allows adding a query OPTION (<setting value>) to the query. You can then
add specific hints that affect how the query runs.
For example:
RemoveTest Controls if the BAQ Designer can return more than 10000 rows while testing
RowLimit BAQs.
This parameter has no affect on other query limits you may specify; it only
controls the data retrieval limit while testing BAQs.
ShowStatistics When this execution setting is set to true, then the system requests Time
and IO statistics from the SQL server while the query runs. The results return
as part of ExecutionInfo table and are shown in the Query Execution
Messages panel as SQL Server statistics.
88 March, 2023
Setting Description
SQLServer Adds SET DATEFORMAT call at the beginning of the query. Only the MS SQL
DateFormat Server should use this setting. Available options:
Timeout Specifies the longest time (in seconds) in which a query can run. Entering 0
for this option turns off the query time limit, and the query can run
indefinitely.
Transaction Isol- Sets transaction isolation level which controls the locking and row version
ation behavior of Transact-SQL statements. These statement are issued by a SQL
Server connection.
Available options:
89 March, 2023
Setting Description
UseAlternate Com- If you upgrade from a pre-10.2.700 Epicor ERP installation and your BAQs
panySecurity have poor performance, use this setting to restore query performance.
Alternately, if you use SQL Server 2016 or older, make sure your query
contains a FOR XML PATH clause. In newer SQL Server versions, you can
replace this clause with the STRING_AGG function.
90 March, 2023
Using Query Parameters
You can filter query data using parameters values. These parameters can be nearly any value that you
can filter against within your query. You can also use parameters to display customized method
arguments for use in Business Process Management (BPM) directives.
91 March, 2023
4. First, enter Parameter Name, such as PartValues.
5. Select Data Type. The available options include nvarchar, int, decimal, date, datetime, bit,
uniqueidentifier and bigint.
6. The Format field displays the default format for the selected Data Type. If you need, you can edit
this value. Be sure this format value follows database conventions.
7. Use the Editor Type drop-down list to select how you will define the parameter values. Available
options:
l Common Editor - Activates the Default Value field. Enter a custom text value you need for
the parameter. The field selected on the criterion then evaluates against this default value.
92 March, 2023
l Radio Button Set - Activates the Values Editor. Use this sheet to define the radio button
options this parameter will use. The field selected on the criterion then evaluates against
these multiple options.
l DropDown List - Activates the Data From drop-down list and the Values Editor. The Data
From defines the type of data you enter on the Values Editor. The field selected on the
criterion then evaluates against the options contained on the drop-down list.
l Item List - Select this option to create the list of values this parameter will use. The field
selected on the criterion evaluates against these item list options.
8. When you select the DropDown List Editor Type, the Data From drop-down list activates. Use this
list to define the source of the drop-down list options. Depend on what option you select, enter
different items in the Values Editor.
Option Description
Custom The Values Editor displays controls for creating a list of values. Define the various
Values list options this parameter will display and use. The field selected on the criterion
then evaluates against these item list options. Enter the following information:
l Value - Enter the actual value of the parameter that is sent to the query.
l Display text - Enter the text that displays for this value on the drop down list.
l Order - Defines the sequential order in which the options display on this drop
down list.
BAQs The Values Editor displays controls for selecting a BAQ. Enter the following
information:
User The Values Editor displays the control for selecting a specific user code.
Codes
User codes are lists of custom values you define through User Defined Codes
Maintenance. When you select a user code, its list of values is compared against the
field selected on the criterion. For more information about creating user codes,
review the Creating User Defined Codes article.
93 March, 2023
94 March, 2023
9. If this parameter is required in order for the BAQ to pull in query results, select the Mandatory
check box.
10. Use the Sequence Order on form field to indicate the order in which parameters display on the
Specify parameters values panel.
11. Select the Skip condition if empty option when you want the BAQ to ignore this parameter
when it returns a blank, or empty, value.
If the parameter is empty, the BAQ ignores the criterion with this parameter. For example, in the
condition StartDate > @param1, the param1 value returns null. If you select the Skip condition if
empty check box, the BAQ does not check the criterion specified for the StartDate field.
You cannot use BAQ parameters that have this property enabled within the
Calculated Field Editor. If a parameter referenced in a calculated field uses this
property, you see the following error message when you analyze or save the query:
"Expression of calculated field <FieldName> references optional query parameter
<ParameterName>."
95 March, 2023
Creating BAQ Parameters in the Query Designer
You can also create parameters as you enter table criteria or subquery criteria within the Query
Designer.
1. Select the table or subquery. In this example, select the Part table.
2. Select either the Table Criteria or SubQuery Criteria tab. In this example, select the Table
Criteria tab.
5. Select the Filter Value drop-down list and select specified parameter.
96 March, 2023
6. Click the specified link.
7. The Select Parameter panel slides on. Select the Add icon .
8. The Query Parameter panel slides on. Enter your new parameter.
DO NOT enter parameter names identical to the following BAQ Constant names:
l CompanyID
l CompanyName
l CurComp
97 March, 2023
l CurCompName
l CurrentCompany
l CurrentCompanyName
l CurrentEmployeeID
l CurrentPlant
l CurrentUserID
l EmployeeID
l GlobalSecurityManager
l IsMultiTenant
l PlantID
l SecurityManager
l UserID
l WorkstationDescription
l WorkstationID
Using Parameters
After you create parameters, use them in your query. In this example, the query lists all the parts in your
database. You want to prompt a user to select a specific part and then filter the BAQ results using this
part parameter.
1. First, define the query parameter. In this example, create a drop-down list that displays specific
part numbers.
98 March, 2023
2. Next, define the table or subquery criteria. In this example, create a table criterion for the Part
table. For Field Name, use PartNum and for the Filter Value, select specified parameter.
99 March, 2023
3. On the Select Parameter panel, select the Parameter ID you created and press OK.
4. When the BAQ runs, the query asks the user to specify the parameter. In this example, the user
selects a part from the list.
Each BAQ always contains one subquery that uses the TopLevel type. This subquery type is required on
all BAQs. If the BAQ has multiple subqueries, they link to the TopLevel subquery. These other
subqueries use different types (INNER, UNION, EXCEPT, and so on) to indicate how they work with each
other to generate result sets.
l Support of widely used query criteria, such as IN ({inner subquery}) or EXISTS ({inner subquery})
l Querying hierarchical data using Common Table Expressions (CTE) with recursion and UNION ALL
l Using CTE and inner subquery in the FROM clause and joins
l Using set operations, like UNION, UNION ALL, EXCEPT, and INTERCEPT
The above set operators are the methods that combine result sets. You create one
TopLevel subquery and use SQL standard keywords to combine its result set with other
subqueries that use different types.
Adding SubQueries
When you construct a query, you can add different types of subqueries and indicate how they relate to
each other. Add a subquery in two ways:
2. You can also create subqueries from the SubQuery List panel. Go to the Overflow menu and
select SubQueries.
Defining SubQueries
You next define how each subquery interacts with the previous subquery. Frequently this is the
TopLevel subquery.
1. When you create a new BAQ, the BAQ designer adds a TopLevel SubQuery1 by default.
2. To change the subquery parameters click the Overflow menu and select SubQueries.
TopLevel Default value for a simple query; each BAQ must contain one main TopLevel
subquery.
Union Selects related information from two tables, much like JOIN. However,
when using UNION, all selected columns need to have the same data type.
With UNION, the BAQ only selects distinct values.
UnionAll Equal to UNION, except that UNION ALL selects all values. The difference
between UNION and UNION ALL is that UNION ALL does not eliminate
duplicate rows; instead it pulls all rows from all tables fitting your query
specifics and combines them into a table.
Intersect Returns the results of two or more selected queries, but it only returns the
rows selected by all queries. If a record exists in one query and not in the
other, the record does not appear in the results.
Except Returns distinct values from the query to the left of the EXCEPT operand
that are not also returned from the right query.
CTE A common table expression (CTE) is a temporary result set defined within
the execution scope of a single SELECT statement. The scope may also
come from a subquery instead of a SELECT statement. CTE subqueries
typically query hierarchical data for recursive queries. Some examples
include a query that displays employees in an organizational chart, or a
query that displays bill of materials data in which a parent part has one or
more components, and those components also have subcomponents or are
components of other parents.
InnerSubQuery Usually added to the WHERE clause of the SQL statement as a nested query
inside another query. You typically use an inner subquery when you know
how to search for a value with the SELECT statement but do not know the
exact value.
7. In the Result Set Rows field, select how data displays in the subquery results set. The available
options include:
l All - default value; the SELECT ALL statement returns all data without restriction.
l Distinct - The SELECT DISTINCT statement specifies that only unique rows can display in
the result set.
l Top - The SELECT TOP statement specifies the number of rows or percent of rows to
return. You can specify either the number or percent of rows the result set displays.
Selecting the With Ties option specifies that the query result set includes additional rows
that match the values in the ORDER BY column or columns in the last row the query
returns. This may cause more rows to return. You can only specify the Top and With Ties
combination in SELECT statements, and only if you specify the ORDER BY clause.
l DistinctTop - The SELECT DISTINCT TOP corresponds to using DISTINCT and TOP clauses
at the same time. The query results set contains top unique rows.
8. When you select the Top or DistinctTop option in the Result Set Rows drop-down list, you can
specify the Top Clause. This disables the Order By OFFSET - FETCH Clause pane.
9. When you select the All or Distinct option in the Result Set Rows drop-down list, the Offset and
Fetch fields activate. Enter values in these fields to get only a window or page of results from the
result set.
select
[EmpBasic].[EmpID] as [EmpBasic_EmpID],
[EmpBasic].[FirstName] as [EmpBasic_FirstName],
[EmpBasic].[LastName] as [EmpBasic_LastName]
from Erp.EmpBasic as EmpBasic
order by EmpBasic.EmpID OFFSET 5 ROWS FETCH NEXT 10 ROWS ONLY
l The number and the order of the fields (columns) must be the same in all subqueries.
l The data types must be compatible through implicit conversion.
l The BAQ takes field aliases from the first subquery; these field aliases must be different in
subsequent subqueries to generate the result set.
To select consistent columns between the previous and subsequent subqueries:
1. In a TopLevel or CTE type, define the set of display column(s). In this example, SubQuery1
displays four columns in this order:
3. Press Display Fields and add the same number of fields to match the previous subquery. The
fields must have the same or compatible data types and display in the same column order. In this
example, the column mapping of SubQuery2: Union looks like this:
l The Alias field displays the field name of the current subquery column. The
subquery takes field aliases from the previous TopLevel or CTE subquery.
l Each SubQuery treats Group By independently. You can construct a BAQ where
only one subquery aggregates data, for example:
3. The Move item(s) to SubQuery panel slides on. The Create New SubQuery radio button is
selected by default. Use this option to create a subquery from the selected item.
The new subquery displays on a separate tab. The selected table or subquery appears on the design
canvas.
3. The Move item(s) to SubQuery panel slides on. Select the Move To Existing SubQuery radio
button.
4. The subqueries available in the current query display. Select a subquery from the grid.
Subqueries are placed in a sequence identified by a number. The sequence number defines the order in
which subqueries run to build the final SQL statement. The exception to this processing are inner
subqueries. If a subquery contains a reference to an inner subquery, the inner subquery generates on
demand and inserts data where the subquery requires it.
Because subqueries concatenate in sequential order, one or more Union, UnionAll, Except,
or Intercept type subqueries can go after TopLevel or CTE subqueries.
Use the SubQuery List to define how the subqueries run to generate the results set:
4. Move the subquery lower in the sequence by selecting the Down arrow .
Top
Inner <- some separate inner SubQuery
Union <- fields are selected according to the Top field list
Top
(Inner <- groups with next Union
Union)<- Fields correspond to Inner SubQuery
In this example, notice the TopLevel subquery displays at the top of the SQL statement, followed by the
second Union subquery.
4. The Copy Subquery panel displays. Either use the New SubQuery Name or enter a different
name.
5. Likewise, the copy function generates tables alias for all the tables in the copied subquery. Either
use the New table names or enter different names.
6. Select Ok.
Advanced Group By Clauses are more complex summarizing expressions. They can do the following:
For example, in an Advanced Group By clause, you can organize the query results so they
display groups of related data. You have a query that pulls in all the purchase orders you
have sent to suppliers in different countries. By using the GROUPING SETS operator, you
organize the purchase orders by country. Each country set then has a total cost for all the
purchase orders, a subtotal cost by country, and a grand total cost.
You create these clauses in the Advanced Group By Clause SQL Editor panel.
ROLLUP The ROLLUP operator generates reports that contain subtotals and totals. It creates a
result set that shows aggregate values through a hierarchy of the selected columns.
One row then generates with a subtotal for each unique combination of (a, b, c), (a,
b), and (a) values. This operator also generates a Grand Total row.
CUBE Generates different types of rows that then combine for display in the query results.
The CUBE operator generates simple GROUP BY rows, ROLLUP aggregate rows, and
rows that cross tabulate these results. The CUBE operator generates one row for each
unique combination of (a, b, c), (a, b), (a, c), (b, c), (a), (b), and (c) values. The operator
generates with a subtotal for each row and a Grand Total row.
GROUPING Generates multiple groups of data into separate sets. Only specified groups aggregate
SETS instead of the entire aggregations that generate by the CUBE and ROLLUP operators.
The results are similar to a UNION ALL relationship for the specified groups.
GROUPING SETS can contain a single element or a list of elements. They can also
create groupings similar to the ROLLUP or CUBE operators. Each GROUPING SET can
contain ROLLUP or CUBE operators.
You can enter expressions that group the data in several ways. Learn more about the
options you can select within the Functions, Operators, and BAQ Constants section in
the Creating Calculated Fields help article.
5. Select Save.
7. Enter a criterion that filters the query results to only display data from the 1032KNUT part:
4. The PartBin_WarehouseCode and PartBin_PartNum fields move to the Display Field(s) grid.
5. Now create the calculated field. Select the Calculated Editor button.
6. The Calculated Fields panel slides on. Select New to add a calculated field.
8. Select the int (integer) Data Type and accept the default Format.
10. Enter the calculated expression in the Text Editor. This expression totals the On Hand Quantities
for the part. Either use the Data and Functions Nav Trees or directly enter the expression.
l sum(PartBin.OnhandQty)
2. The Advanced Group By Clause SQL Editor panel displays. Select New to add a clause.
3. Enter the Advanced Group By clause. Either use the Functions Nav Tree or directly enter the
clause. Enter the ROLLUP operator and the Warehouse Code and Part Number you selected to
display.
l ROLLUP(PartBin.Warehouse, PartBin.PartNum)
6. Select the Analyze Query button to make sure the syntax is correct.
8. The ROLLUP clause shows how many parts are in each warehouse and then the subtotal quantity
for the warehouse. The last row displays the grand total quantity.
l CUBE(PartBin.Warehouse, PartBin.PartNum)
5. The query results show all the different expressions. Each warehouse displays its subtotal
quantity for part 1032KNUT. It then shows the grand total quantity. For the next part of the cube,
You can use either the InnerSubQuery or CTE subquery types to aggregate data using the
PIVOT and UNPIVOT operators. When you use a CTE subquery, place it as the first
subquery. It provides the base data for the rest of the query expression.
5. Select OK.
That is all you do to the TopLevel subquery for now. Later you will add the PIVOT expression to this
TopLevel subquery.
3. Go to the Tables panel. Use the Search field to find the OrderHed table.
6. Either double-click or drag the Customer table to the design canvas. These tables share a logical
link in the database, so a line displays this JOIN relationship.
10. Return to the Available Tables drop-down list and select OrderHed.
11. Go to the Available Fields grid and find OrderNum. Click the Right Arrow button to move this
field to the Display Field(s) grid.
5. Now either accept the default value or enter the Format you need.
7. Either use the Data and Functions Nav Trees or directly enter the calculated expression. This
expression locates the year during which each order was entered into the database:
l datepart(year,OrderHed.OrderDate)
6. Go to the PIVOT aggregate formula field and select the wrench icon.
7. The Pivot Aggregated Expression Editor panel slides on. Go to the Data Type drop down list
and select Int.
9. This panel is similar to the Calculated Fields panel, as it has both Data and Functions Nav Trees.
Either use the Nav Trees or directly enter the calculated expression. If you use the Nav Trees, add
items by either double-clicking or dragging them into the text editor. This expression counts how
many orders were entered in the database:
l count( OrderHed_OrderNum )
You are not limited to using only the functions from the Nav Tree. Any function
supported by the SQL Server that Kinetic uses can also be in your expression. In
External BAQs, use functions supported in the database server from where the
external BAQ runs.
11. Now specify the FOR clause for the PIVOT statement. In this example, you define which years you
want in the output. Go to the Pivot column and select the Calculated_OrderYear column. You
created this calculated field to return the year during which each sales order was entered.
13. Click on the Filter Value drop down list and select specified constant list.
15. The Enter Value List panel slides on. Select New to add a value.
16. Enter a value for each year that you want to include in your query results.
2. Select the fields you wish to display on your query results. From the Available Tables drop down
list, select InnerSubQuery.
3. Select the CustID field and all the years you entered within the value list.
For the Display Columns, do not add fields used in the PIVOT formula or in the FOR
clause. You can select other columns from the source subquery, like the value list,
for display.
7. The Query Results grid shows all the customers in your database and how many orders each
customer placed during each year you included in the query.
3. The Sub Query panel slides on. Enter a Name like InnerSubQuery.
6. Now add the UD01 table to the InnerSubQuery. Go to the Query Designer.
l UD01_Company
l UD01_Key1
l UD01_Key2
l UD01_Number01
l UD01_Number02
l UD01_Number03
l UD01_Number04
l UD01_Number05
5. The UnPivot SubQuery FOR Clause tab displays below the design canvas.
6. Go to the PIVOT aggregate formula field and select the wrench icon.
7. The Unpivot column name panel slides on. Go to the Data Type drop-down list and select
Integer (int).
9. Enter the Name that helps you identify the column, such as Numbers.
11. Enter the Pivot column. This is the column that will contain all unpivoted column names. For this
example, enter Field.
14. The Specify table fields panel slides on. Select New to add a field.
l UD01_Number03
l UD01_Number04
l UD01_Number05
2. Select the fields you wish to display on your query results. From the Available Tables drop down
list, select InnerSubQuery.
l UD01_Company
l UD01_Key
l Field
7. The Query Results grid shows all the numbers within the UD01 table. The UNPIVOT expression
display each number on a separate row.
Run the data controls to verify that the data results you need populate on this grid. If you are not seeing
the results you want, you can return to the Query Builder to modify the query and then test the results
again.
Analyzing a Query
1. Select Run Query.
2. Press Analyze Query.
3. The Problems panel displays the response from the server, indicating whether the syntax is
correct. If the BAQ Designer detects any SQL syntax errors, the panel displays the message
corresponding to error.
Testing a Query
1. To set the maximum number of rows returned by the query, you can select a value from the
Rows to Return list. The available options include All (default), 10, 50 and 100.
On-premise installation note: this feature is only available for BAQs executed in an
MS SQL database. The SQL Server account used by your Kinetic installation must be
provided with the ALTER ANY CONNECTION and VIEW SERVER STATE permissions to
cancel query execution.
Technical Details
When using Analyze, Test, and Get List buttons, as well as when the query runs, the query checks its
tables and displays the query results.
For standard tables, which are in the Ice or ERP database schema, the BAQ Designer verifies the tables
publish through zData and that the query syntax runs without errors. For Extension set tables that are
installed in the system, but disabled or not mapped in the current company, a warning message
displays in the Query Execution Messages pane, but the BAQ Designer still runs the query. On SaaS
installations, only global security managers can run the XXXChunk/XXDef tables.
If an extension table belongs to an unknown Extension set, the BAQ Designer does not run the query
and it does not save your changes. An error message displays in the Query Execution Messages pane.
l Be careful if you decide to modify the query, as any changes impact other
applications that use this query.
l If you attempt to delete a query that is in use, a warning message displays verifying
whether you want to continue deleting it. Typically, you should not delete any
query in use unless it is obsolete or no longer needed. After you delete the query,
remove or update the dashboard, BAQ report, or other items that previously used it.
l If several dashboards use the current query, you should not change it. Instead
create a new shared query that contains the changes you need. Other users can
then decide if they want to use your new query in their dashboards, reports, and
other items.
2. The Used - [Query ID] panel slides on. By default, the grid displays ALL items.
1. The open tabs display on a bar across the top of the BAQ Designer, just below the Crumb Bar.
4. All the tabs close except for the tab that displays the Query Identification and Query Phrase
cards.