MSSQL Server query to piechart

Hi folks, I have got a result like this.
|time|value|metric|
|1555452458|201|WOMAN|
|1555452458|501|NULL|
|1555452458|1958|MAN|

ı tried many things but i couldn’t make it.
SELECT
count(*) as value,
Gender as metric
FROM
[dbo].[BI_people]
GROUP BY Gender

how can i able to use this query as a pie chart. i am getting an error when i changed to table to time-series

Many thanks. i know a lot of people asked before most of them on mysql. i can execute my tsql query succesfully but grafana throw an error metric type: NVARCHAR but datatype is .

what is the point.

Best,

In this article, https://grafana.com/docs/features/datasources/mssql/, it looks like the metric is in the database with NVARCHAR(# of characters). The (.) or period/point error looks to be saying that no NVARCHAR is defined.

Is the NVARCHAR value defined in your db for Gender?

1 Like

Also had issues creating a pie chart from MS SQL.

My solution was to use multiple queries in the panel

SELECT
count(Gender) AS Gender
FROM
[dbo].[BI_people]
WHERE Gender = MALE

SELECT
count(Gender) AS Gender
FROM
[dbo].[BI_people]
WHERE Gender = FEMALE

1 Like

$__unixEpochTo() function solved my problem. thanks for your help.

SELECT
$__unixEpochTo() AS time,
count(GENDER) as value,
cast(GENDER as nvarchar(max)) as metric
FROM
[dbo].[BI_people]
GROUP BY GENDER

2 Likes