# Handle empty result set with Stat visualisation

**URL:** <https://community.grafana.com/t/handle-empty-result-set-with-stat-visualisation/72202>\
**Category:** Stat Panel\
**Tags:** polystat, dashboard\
**Created:** [September 12, 2022, 10:30am UTC](https://community.grafana.com/t/handle-empty-result-set-with-stat-visualisation/72202 "2022-09-12T10:30:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dgoloughlin](https://avatars.discourse-cdn.com/v4/letter/d/a9adbd/32.png) [@dgoloughlin](https://community.grafana.com/u/dgoloughlin)\
**Post date:** [September 12, 2022, 10:30am UTC](https://community.grafana.com/t/handle-empty-result-set-with-stat-visualisation/72202/1 "2022-09-12T10:30:44Z")

</div>

- Grafana version: 8.3.3
- Visualization: Stat
- Data source type & version: Microsoft SQL Server 2019
- OS Grafana is installed on: Windows
- User OS & Browser: Edge

I’m using variations of the following query to display the health status of an application. I’m also taking advantage of the time series feature that automatically maps the third parameter (metric) to the name assigned to the second parameter (healthy).

When there is data this mostly works as you can see.

 ![mops-working.PNG](https://us1.discourse-cdn.com/grafana/original/3X/f/0/f0928d92c755f9107a5d836a55a11fa23d1f85c4.jpeg)

When there is no data both the first and the second parameter are shown.

 ![mops-broken.PNG](https://us1.discourse-cdn.com/grafana/original/3X/2/c/2c9778a9262cf56b9fb5256bf366d5f0342c56b7.jpeg)

Ideally I’d like to display the health status of an application with no data as unhealthy.

I get the feeling that I need to implement this another way because if there’s no data Grafana can’t know the name of the metric?

```auto
SELECT $__timeEpoch(AUDIT_TIME),
       CAST(HEALTHY AS INT) AS healthy,
       APP_NAME AS metric
FROM ima.dbo.HEALTH_CHECK_RULE
         INNER JOIN ima.dbo.HEALTH_CHECK_METRIC m ON HEALTH_CHECK_RULE.RULE_ID = m.RULE_ID
WHERE $__timeFilter(AUDIT_TIME)
  AND APP_NAME = 'mwproxy'
  AND RULE_NAME = 'All checks'
ORDER BY AUDIT_TIME ASC

```

---

<div class="post-metadata">

**Author:** ![yosiasz](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/yosiasz/32/45847_2.png) [@yosiasz](https://community.grafana.com/u/yosiasz)\
**Post date:** [September 12, 2022, 5:02pm UTC](https://community.grafana.com/t/handle-empty-result-set-with-stat-visualisation/72202/2 "2022-09-12T17:02:04Z")

</div>

Welcome

Please provide DDL and DML for both tables?

```auto
create table #HEALTH_CHECK_RULE --etc
create table #HEALTH_CHECK_METRIC --etc

insert into #HEALTH_CHECK_RULE values()

insert into #HEALTH_CHECK_METRIC values()

```

We don’t have access to your database so impossible to provide some guidance.

---

<div class="post-metadata">

**Author:** ![dgoloughlin](https://avatars.discourse-cdn.com/v4/letter/d/a9adbd/32.png) [@dgoloughlin](https://community.grafana.com/u/dgoloughlin)\
**Post date:** [September 12, 2022, 11:42pm UTC](https://community.grafana.com/t/handle-empty-result-set-with-stat-visualisation/72202/3 "2022-09-12T23:42:43Z")

</div>

I’ll answer my own question 😉

I’ve realized that I don’t actually need a series, I just need the value of the most recent metric. I get a better result when I let the database find it for me and let Grafana format the result set as a table.

```auto
SELECT CAST(HEALTHY AS INT) AS mwproxy
FROM ima.dbo.HEALTH_CHECK_METRIC a
         INNER JOIN
     (SELECT MAX(METRIC_ID) id
      FROM ima.dbo.HEALTH_CHECK_RULE
               INNER JOIN ima.dbo.HEALTH_CHECK_METRIC m ON HEALTH_CHECK_RULE.RULE_ID = m.RULE_ID
      WHERE APP_NAME = 'mwproxy'
        AND RULE_NAME = 'All checks') b ON a.METRIC_ID = b.id

```
