hi, i’m using MS SQL along with the Discrete panel. I’m looking to figure how to use what i saw my searching about and reading some docs the __from and _to instead of $__timeFilter. i’m trying to add on previous hours or days to the timeframe query that gets selected from the Grafana UI for the panel.
here is my query example I’m using today in the Discrete panel:
SELECT
$__timeEpoch(line_datetime),
case
when line_status = 'OFFLINE' then 0
when line_status = 'ONLINE' then 1
end as value,
line_name as metric
FROM
line_status
WHERE
$__timeFilter(line_datetime) AND line_name = 'XYZ'
ORDER BY
line_name ASC
so, if i look at Generated SQL the WHERE looks like so.
WHERE
line_datetime BETWEEN '2020-10-01T04:00:00Z' AND '2020-10-07T03:59:59Z' AND line_name = 'XYZ'
I can do this in MS SQL
WHERE
line_datetime BETWEEN DATEADD(DAY, -1, '2020-10-04T23:56:15Z') AND '2020-10-05T23:56:15Z' AND line_name = 'XYZ'
and i get the previous day tacked on to the FROM date/time…
So i tried to implement this in Grafana as:
line_datetime BETWEEN DATEADD(DAY, -1, $__from) AND $__to AND line_name = 'XYZ'
then as
line_datetime BETWEEN DATEADD(DAY, -1, ${__from}) AND ${__to} AND line_name = 'XYZ'
but the query doesn’t resolve and i get no error only
Object
request:Object
url:"api/tsdb/query"
method:"POST"
data:Object
from:"1601814358902"
to:"1601987158902"
queries:Array[1]
hideFromInspector:false
response:Object
results:Object
A:Object
so how can i call out the TO and FROM variables within the timeFilter or am i going about this the wrong way ? thanks