To obtain data for your reports (and lookups), Mercury must query your database(s).
Depending on the Connection used for your report or lookup, there will be one or more of the following query-types available. (For more on Connections, see Admin > Connections.)
Stored Procedure
View
Statement (SQL)
Web Service Query (aka “Query") (used by Business Central connections)
CodeUnit queries (used by Business Central connections)
When creating a report (see Admin > Reports) or a Lookup (see Admin > Lookups), you will:
In the New-Report form, the Query-Type is part of the “Report Source” specification that follows the Connection.
In the Lookup form, the Query-Type is part of the “Data Source” specification that follows the Connection.
Most queries are authored by database administrators or developers. If you don’t know what query is needed for a particular report, check with your IT department.
The most powerful query type – but also the most complex. Procedures are miniature “programs'' that live inside your database and are typically authored by a database administrator or developer.
A stored procedure specifies the parameters it uses (if any). Parameter values for stored procedures are required (cannot be blank) and will automatically appear in Mercury’s Parameters grid, both when a report definition is being created or edited by an admin-user (see Admin > Reports), or when the report is being run by a user.
A Lookup cannot use parameters. Therefore, any stored procedure that includes parameters cannot be the basis for a lookup.
A View also lives inside your database but is simpler to create and is less powerful than a stored procedure. Views do not explicitly specify parameters, but Mercury allows you to designate any field(s) in the View to be used as a “parameter” available to the end-user running the report. But unlike the parameters of a stored procedure, View parameters are optional – at runtime, the user doesn’t have to supply a value.
A Statement query-type consists of one or more database query statements (using standard SQL syntax). Unlike Procedures and Views, Statements don’t reside in your source database. They’re stored as a part of Mercury’s report-definition and must be written or pasted directly into the field located to the right of the pencil icon. Alternatively, click the pencil icon and Mercury provides a Statement Editor that makes it easier to enter, test and edit your query. If you’re familiar with SQL you can write queries yourself, or your IT developer can provide a query for you.
Statement Queries entered directly into Mercury can be managed using the Statement Editor.
Access the Statement Editor by clicking the pencil icon shown below.
Paste or Type a Statement Query into the frame on the left.
Optional: click Format to apply typical formatting to your query – line breaks, indentation, and so on.
Optional: Test the query by clicking the Validate button. This gives you a chance to find errors before you actually try to run the query and retrieve data.
If Mercury returns the result “Valid” then proceed to the next step.
If Mercury returns the result “Invalid”, review the Statement and make the necessary corrections.
Complete the testing by clicking the Execute button. Results will appear in the frame on the right.
Save time testing Queries that return large amounts of data with the built-in filter, Top:. Just set the number of records you wish to have returned and click Execute.
Database Platform | Parameter Prefix |
Microsoft SQL Server | @ (at sign) |
MySQL | @ (at sign) |
Actian / Zen | : (colon) |
SQLite | @ (at sign) |
Text files (CSV, other) | @ (at sign) |
This is a query that’s similar to a View, but which takes place via an internet (or intranet) web-service connection. This type of query is available through platforms such as Business Central. In Mercury this may be shown simply as a “Query”.
Also available through Business Central, a CodeUnit query is a special program that resides within your Business Central database and is typically created by a specialized developer. You can think of it as a special Business Central version of a stored procedure.
Here’s a create-new-report screenshot that uses an SQL Server Connection (the connection is named “Wonderland” in this example). The available query-types for this Connection are StoredProcedure, View, and Statement.
Here’s a create-new-report screenshot based on a Business Central connection (the connection is named “Mercury-D365-BC” in this example). The available query-types for a BC connection are Web-service Query (“Query”) and CodeUnit.
As noted previously, the query-type (and the name of the query, if it’s not a Statement) is chosen by the author of the query – typically an IT person.
If you can’t find the query you’re looking for when creating a new report or a lookup: