Using a variable in MySQL query

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?


  • 0
    Kiersten Nelthorpe

    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.

  • 0
    Meggan King

    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. 



    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,


Please sign in to leave a comment.