I want to query an SQL data source using Flux, but date filters should be dynamic. So, I created a type time flux object and convert it into string and used it in the query. Still, it didn’t work out for “-7d”.
Essentialy, it should run as a task and read data from the source in defined periods .So, please share if there is a better way to write this.
_start = string(v: now()) //This works fine.
_start = string(v: 2021-05-01) //This works fine too.
_start = string(v: -7d) //This one doesn't.
query = "SELECT ... FROM ... WHERE date_field > '${_start}' "
I want to query an SQL data source using Flux, but date filters should be
dynamic. So, I created a type time flux object and convert it into string
and used it in the query. Still, it didn’t work out for “-7d”.
You need to ensure that whatever you pass to MS SQL (I assume you mean that
you are using Microsoft SQL Server) is a valid MS SQL query.
_start = string(v: now()) //This works fine.
_start = string(v: 2021-05-01) //This works fine too.
_start = string(v: -7d) //This one doesn’t.
query = "SELECT … FROM … WHERE date_field > ‘${_start}’ "
Maybe MS SQL has a date_sub() function similar to MySQL’s?