How do I properly use custom variables in a MySQL query as a data source? I am trying the following:
WHERE T.created >= {props.startDate.format()}
I get a SQL syntax error, so I am guessing this is not the right way to access a variable?
How do I properly use custom variables in a MySQL query as a data source? I am trying the following:
WHERE T.created >= {props.startDate.format()}
I get a SQL syntax error, so I am guessing this is not the right way to access a variable?
I sort of got it to work by setting a default value in the Variable list inside the Advanced menu of a Klip. But it is not updating when user input updates the start date variable on the dashboard.
Hi Kiersten,
Your format is not quite correct. If your variable is called startDate, then you reference it as {props.startDate} In the Klip editor variable value and the output of the variable must be in the expected date format for your query. Please refer to this document for details: https://support.klipfolio.com/hc/en-us/articles/216183237-BETA-Working-with-dynamic-data-sources
It is advised to not use dates as properties in queries. If you want to use a date in your query - such as today, yesterday, or a rolling window (previously 6 months - today), then you should use our date query parameters and not variables.
https://support.klipfolio.com/hc/en-us/articles/216181877-Date-parameters-in-data-source-queries
Using custom variables in a data source (first example above), will generate many data source instances behind the scenes and this can impact how your database responds and handles all the requests.
Hope this helps,
Meggan
Hi,
I'm trying to do something similar. I'm creating a data source using a SQL query that depends on the dates selected by the user in the dashboard:
Hi Matteo,
Thanks for your question!
If your variable is called date_start, then you reference it as {props.date_start}. Additionally, in the Klip editor variable value and the output of the variable must be in the expected date format for your query. Please refer to this document for details: https://support.klipfolio.com/hc/en-us/articles/216183237-BETA-Working-with-dynamic-data-sources.
Once you've gotten your variable formatted properly for this query (both with the props. prefix) and the proper date formatting as expected by your db, you should be able to get this data source working!
Best,
Parker
Hi Parker,
Thanks for your answer, but I'm not working with any "Klip", I don't know where to find that section.
I only see "Data sources" or "Metrics" in the menu.
On the data source creation is where I need to use a variable, I need the dates to be taken from the dashboard dates: