Creating Query Reports
This guide walks through building a QUERY view type report: defining the SQL statement, setting viewer access, and saving the section. The examples in the reference videos include get_active_loans and sumo-user-guide.
Prerequisites
- Access to Settings → My reports in Report Builder.
- A new query report created via Add New Report, or an existing query opened through the row gear icon.
Add Section — Query Configuration
After creating a new Query report (or opening an existing one), the Add Section editor opens. The breadcrumb reads New Report → Add Section.
Section Fields
| Field | Description |
|---|---|
| Name | Internal section name. Becomes the report title in the render view (for example, get_active_loans). |
| Description | Optional explanation of what the query returns. |
| View Type | Set to QUERY for SQL-based sections. |
| Viewers | Controls which users or roles can see this section. Select one or more viewer groups from the dropdown. |
Writing the SQL Query
- Scroll to the SQL editor at the bottom of the Add Section page.
- Enter a valid
SELECTstatement against the ledger database.
Example: Active Loans Query
The following query retrieves all records from the loan_accounts table type:
SELECT
*
FROM
table_data
WHERE table_type_id = 'loan_accounts'
Example: User Holdings Query
A more advanced query selects and casts specific columns from the user_holdings table type:
SELECT
CAST(h.freecode1 AS TEXT) AS user_id,
CAST(h.freecode2 AS TEXT) AS scrip_name,
CAST(h.total_qty AS TEXT) AS total_qty,
CAST(h.pledged_qty AS TEXT) AS pledged_qty,
CAST(h.total_qty - h.pledged_qty AS TEXT) AS available_qty,
CAST(h.latest_price AS TEXT) AS latest_price
FROM (
SELECT DISTINCT ON (freecode1, freecode2) *
FROM table_data
WHERE table_type_id = 'user_holdings'
ORDER BY freecode1, freecode2, value_date DESC
) h
- Use meaningful column aliases — action field mappings and export columns rely on the names returned by the query.
Saving the Query Section
- Review the Name, Viewers, and SQL statement.
- Click Save (floppy disk icon) at the bottom-right of the SQL editor.
- The section is persisted and the report becomes available in the View List.
To discard unsaved changes, click Delete (trash icon) or close the section using the X button in the breadcrumb area.
Testing the Report
After saving, verify the report from the end-user portal:
- Navigate back to the Report Builder home page (View List).
- Locate the new report by ID and name (for example, 3456 — sumo-user-guide).
- Click the report row to open the render view.
- Click Run Query and confirm the expected columns and rows appear.
- Optionally click Export Excel to validate the export output.
See Running Reports for the full end-user procedure.
Optional Next Steps
| Task | Guide |
|---|---|
Add runtime filters (account_id, boid, etc.) | Parameters and Actions |
| Link rows to Form Config workflows | Parameters and Actions |
| Reference the view from a process | Report Stage in Process documentation |
Important Notes
- Query section Name should be descriptive and unique within the report.
- Always assign Viewers before publishing — unrestricted views may expose sensitive ledger data.
- Test with Run Query after every SQL change to catch syntax errors before users access the report.
- Column names returned by the SQL query must match the field names used in action mappings.