# Send a Slack alert from SQL only when a condition is met | DRE

> Post a message to Slack or email only when a SQL result crosses a threshold, with a when: condition; on quiet days nothing is sent.

[← All use cases](https://getdre.com/use-cases/)

# Send a message only when it matters

A daily “all fine” message trains people to ignore it. With when:, the message is sent only when the data calls for it, and on quiet days the run records it as skipped, not failed.

[Try it yourself: Conditional Slack headline](https://github.com/get-dre/dre/tree/v0.5.1/examples/slack-headline/)

Recorded from real runs: the quiet default is skipped, then the Slack Set sends the alert.

Recorded from real runs: the quiet default is skipped, then the Slack Set sends the alert.

![A Slack message: Regions under €30,000, two regions under target with their net revenue](https://getdre.com/media/alert/slack.webp)

The alert in Slack (a real screenshot of a test workspace, cropped to the message).

reports/messages/msg\_alerts/msg\_alerts.yml

```yaml
queries: [msg_low_regions]
output:
  - name: alert
    format: message
    when: "results.msg_low_regions.row_count > 0"
    title: "Regions under {{ var('alert_below') | currency('EUR') }}"
    text: |
      **{{ results.msg_low_regions.row_count }}** region(s) under target:
      {% for r in results.msg_low_regions.rows %}- {{ r.region_name }}: {{ r.net | currency('EUR') }}
      {% endfor %}
    destination: {profile: teams_mock}
  - name: note
    format: message
    text: "{% if results.msg_low_regions.row_count %}Low regions: {{ results.msg_low_regions.columns | join(', ') }}{% endif %}"
    destination: {profile: gchat_mock}
default_set: msg_quiet
sets:
  - {name: msg_quiet, vars: {alert_below: 0}}
  - {name: msg_loud, vars: {alert_below: 100000000}}
  - name: msg_slack
    vars: {alert_below: 30000}
    output: {name: alert, destination: [{profile: slack}]}
```

reports/messages/msg\_alerts/msg\_low\_regions.sql

```sql
select region_name, net from {{ ref('delivery_sample') }}
where net < {{ var('alert_below', 0) }}
order by net
```

terminal

```bash
dre run msg_alerts                  # threshold 0: both outputs skipped
dre run msg_alerts --set msg_slack  # under €30,000: the alert goes to Slack
```

### What to notice

-   A false when: skips the output: nothing is written or sent, and run\_results.json says skipped.
-   A text that renders empty is skipped the same way: the note output uses {% if %} instead of when:.
-   In the demo, alert and note go to Teams and Google Chat webhook mocks; the msg\_slack Set sends the alert to Slack.
-   DRE keeps nothing between runs: it says it every day the data shows it. Alerting on failed runs belongs to your orchestrator.

### In the docs

-   [Sending only when it matters →](https://getdre.com/docs/messages/#sending-only-when-it-matters)

## More examples

[

### Save to a Databricks Volume or workspace

Write the file to a Unity Catalog Volume or a workspace folder, from your laptop or inside a job.

](https://getdre.com/use-cases/databricks-volume-and-workspace/)[

### Run by schedule name

Name a timing once and share it; your orchestrator runs dre run --schedule, and a rerun renders the same SQL.

](https://getdre.com/use-cases/run-by-schedule-name/)[

### Deliver to many destinations in one run

One workbook: local copy, SFTP, S3, GCS, Azure Blob and an email, in order, in a single run.

](https://getdre.com/use-cases/deliver-to-many-destinations/)
