Named Query by Drop Down List for Month in the Vision Module

Hey Guys,

I'm having a problem with pulling the Value from the drop down list and populating that value into my Named Query. I'm not sure what I'm doing wrong.


My Selected value for September is an Integer of 9, but when my Query tries to run it faults out saying:
Conversion error: query returned "Date", binding needs "Integer" on query binding for "Table Testing.Root Container.Dropdown.selectedValue"

I'm not sure why since what I'm pointing to is an integer. I'm sure it's something simple I am doing wrong.

Is the binding in your screenshot the binding that's visible on selectedValue?

Explain what you're trying to do in more detail, because currently there's a binding trying to set the month value from the query result.

1 Like

What is the Select statement. Maybe it is talking about what SQL returned?

1 Like

@PGriffith Yes, sorry I should've made that clear. The drop down list has September selected which is a value of 9. Making the Selected Value 9. This is set-up as an integer, which is what my database wants.

Here's my SQL Query code where I'm trying to select my time frame. Which works when I do a Testing Query.

WHERE MONTH(Time_Stamp) = :Month AND YEAR(Time_Stamp) = :Yeartype or paste code here

maybe Yeartype is returning a Date not Int?

We're talking past each other, I think.

From the two screenshots you originally posted, you've got a binding on yourDropdown.selectedValue. A binding is used to provide a value - so if the binding on that property is in fact the named query binding you're showing in your other screenshot, what's happening is that as soon as you open the window, the query is being run (with whatever selected value was last saved in the designer being fed into the query) and then the query is running and trying to mash the first row/first column's result into the selectedValue property of your dropdown.

That is almost certainly not what you want. If you want to trigger a named query when the dropdown's selected month changes, which is what you actually do want, I suspect, you need to use a script, not a binding.

What I wanted to do was select the month, and year of the data, insert that information into the Query. Then have a separate button to actually trigger the query with the inserted date/year.

image

That way the Query would only trigger when the button was pressed. Is this feasible with a Named Query or only via Scripting.

Using a named query is correct, but to do it in the way you are describing, the named query will need to be called from the actionPerfomed event handler of your button. Just pass the selected values from the dropdowns into the parameter dictionary that gets passed into the named query when it is called:
https://docs.inductiveautomation.com/display/DOC81/system.db.runNamedQuery

1 Like