Daily SQL Report Email
On a daily schedule, query all rows from a SQL table (e.g., open support tickets), format them into an HTML table, and email the summary to a distribution list.
Provided as-is, without warranty of any kind. Review and test each pattern in a non-production environment before deploying it to live automations. See our Terms.
Overview
FlowLibs - Daily SQL Report Email is an intermediate-level scheduled flow that queries a SQL Server table for open records daily and delivers a professionally styled HTML email report to a distribution list. It demonstrates SQL Server connector integration, dynamic HTML table generation, conditional email branching, and environment variable-driven configuration.
Use Case
Operations and project management teams need daily visibility into open support tickets (or any SQL-based dataset) without requiring Power BI licenses or dashboard access. This flow automates the delivery of a summary report directly to their inbox every morning, ensuring no open items are overlooked.
Flow Architecture
Recurrence - Daily 8AM
RecurrenceFires every day at 8:00 AM Eastern Standard Time.
Init varSqlTableName
Initialize variableReads the `flowlibs_SQLReportTableName` env var (default: `[dbo].[SupportTickets]`).
Init varFilterExpression
Initialize variableReads the `flowlibs_SQLReportFilterExpression` env var (default: `Status eq 'Open'`).
Init varReportRecipients
Initialize variableReads the `flowlibs_DailyReportRecipients` env var (default: `operations@contoso.com`).
Init varHtmlRows
Initialize variableEmpty string variable used to accumulate HTML table rows.
Get SQL Table Rows
SQL Server - GetItemsQueries the configured table with the OData filter, returning up to 500 rows.
Compose Row Count
ComposeCalculates `length()` of the returned array to determine how many records were found.
Check If Rows Exist
If conditionBranches based on whether the row count is greater than zero.
- Loop Through Rows — ForEach iterates over results, appending a styled HTML `<tr>` per row (TicketID, Title, Priority, AssignedTo, CreatedDate) to `varHtmlRows`.
- Compose HTML Report — Builds a complete styled HTML email with gradient header, record count badge, 5-column data table, and footer showing table/filter info.
Environment Variables
| Schema name | Type | Default | Description |
|---|---|---|---|
| flowlibs_SQLReportTableName | String | [dbo].[SupportTickets] | SQL Server table to query (fully qualified, e.g., `[dbo].[SupportTickets]`). |
| flowlibs_SQLReportFilterExpression | String | Status eq 'Open' | OData filter applied to the GetItems action. |
| flowlibs_DailyReportRecipients | String | operations@contoso.com | Semicolon-separated email distribution list that receives the daily report. |
Connectors & Connections
| Connector | API name | Actions used |
|---|---|---|
| SQL Server | shared_sql | GetItems (query table rows with OData filter) |
| Office 365 Outlook | shared_office365 | SendEmailV2 (deliver report and no-records notification) |
Note — All connections are referenced as solution connection references; the flow is portable between environments as long as a connection is mapped at import time.
Customization Guide
Almost every realistic variant of this flow can be implemented by changing environment variable values. A few cases require small edits inside the flow definition — those are called out explicitly below.
- Change the SQL table
- Update the flowlibs_SQLReportTableName env var to point to any table (e.g., [dbo].[Orders], [dbo].[Incidents]).
- Adjust the filter
- Modify flowlibs_SQLReportFilterExpression to any valid OData expression (e.g., Priority eq 'High', CreatedDate gt '2026-01-01').
- Change recipients
- Update flowlibs_DailyReportRecipients with semicolon-separated email addresses.
- Customize HTML columns
- Edit the Append HTML Row action inside the ForEach to map different column names from your SQL table.
- Change schedule
- Modify the Recurrence trigger frequency, time zone, or schedule as needed.
- Adjust row limit
- The GetItems action is set to $top: 500; adjust this limit in the action parameters.
Key Expressions
The flow is intentionally light on Power Fx / WDL gymnastics — the heaviest expressions are the branch-name concatenation and the approval outcome check. They are listed below in the order they appear in the flow.
EXPR.01Row count
Counts the rows returned by the SQL Server GetItems action.
EXPR.02Null-safe column access
Safely accesses a column inside the ForEach, falling back to 'N/A' when null.
EXPR.03Dynamic email subject
Builds an email subject that includes today's date and the record count.
EXPR.04UTC timestamp in report
Used in the HTML report footer to show when the report was generated.
Comments
Sign in to join the conversation.
Sign inNo comments yet. Be the first to share your experience with this flow.