Db query error: mssql: Incorrect syntax near the keyword 'AS'

Hello Everyone,

SELECT
DK_KOD, $__time(DATEADD(HOUR, -3, MQ_TAR_ZMN)),
SUM(ADET) AS toplam
FROM
[MYDB].[dbo].[Sayi]
WHERE
DK_KOD = ‘XYZ’
AND (TXN_KOD = ‘A’ OR TXN_KOD = ‘B’ OR TXN_KOD = ‘C’
OR TXN_KOD = ‘D’ OR TXN_KOD = ‘E’
OR TXN_KOD = ‘F’ OR TXN_KOD = ‘G’)
GROUP BY
DK_KOD, DATEADD(HOUR, -3, MQ_TAR_ZMN)
ORDER BY
DATEADD(HOUR, -3, MQ_TAR_ZMN)

As a result of this query I sent to SQL Server data source in Grafana, I got an error

db query error: mssql: Incorrect syntax near the keyword ‘AS’

I removed the AS keywords and it didn’t help, I tried whatever chat gpt suggested and it didn’t work.

Can you help me with this? I want to plot the data result as a time series in Grafana version: 9.3.6.

Thank you in advance

try put the column alias in double quotes:

SELECT
DK_KOD, $__time(DATEADD(HOUR, -3, MQ_TAR_ZMN)),
SUM(ADET) AS “toplam”

Unfortunately it didn’t work.

try square brackets?

as [toplam]

click on Query Inspector and what does the generated query look like, post it back here