Report Data Query not working

I am trying to run a simple report with a Startdate and enddate Parameter, and using a query as my source. Here is the Query:

SELECT ambientHum,
ambientTemp,
valveDischarge,
valveKing,
t_stamp
FROM refrigeration Where t_stamp between StartDate
and EndDate

The StartDate Parameter value is {[default]ref_startDate}
The EndDate Parameter value is {[default]ref_endDate}
They are both Date Type values.

The Query runs fine without the “Where” clause, but will not run with it. My StartDate and Enddate are linked to two memory tags that are tied to a dropdown calendar. They are working because their values show up in the sample data. If I replace the parameters with real Dates, they work. The only thing I can think of is that the Query itself cannot see that they are variables. How do I fix this, if anyone knows?

When you configure the Query data source and you want to use parameters you need to indicate that a parameter is to be used with a ?. When you do this you will be presented with a place to enter the value of the parameter.

Your query should look like:

SELECT ambientHum,
ambientTemp,
valveDischarge,
valveKing,
t_stamp
FROM refrigeration
WHERE t_stamp between ? and ?

See this doc page for more info:
https://docs.inductiveautomation.com/display/DOC81/SQL+Query+Data+Source

1 Like

Tried it like you showed. Put the parameters in the correct boxes but still will not work. I have the parameters linked to memory tags that are created from a calendar dropdown. They show up in the sample data, but the query itself refuses to see them.
image

Your screenshot appears to be from the report preview, which is going to use the parameter default values not your dropdown values. There’s really no magic happening, the query cannot refuse to use your parameters if they are used in your where clause. Are you getting an error? Can you show your actual code (please use preformatted text </> button) and your parameter config?

I found my problem. When putting the parameter names in the windows, I was not putting them in Brackets {}, which is why they would not work.

Thanks for the help.

1 Like