Turning where clauses on or off

Hey all,

I am making an alarm page on one of my screens where I can sort alarms by the alarm type, but I would also like to show all of the alarms for the given time range. I have a drop down box with the following SQL statement bound to it:

SELECT DISTINCT STATE_NAME FROM ALERT_LOG where displaypath='Kill Floor Alarms' union all select 'All' order by STATE_NAME asc

So that it will pick all of the different alarms that are in the alarm database associated with “Kill Floor Alarms”, I also have it adding an “All” selection to the list.

Now, on my table I have this SQL statement:

SELECT STATE_NAME, ACTIVE_TIMESTAMP, CLEARED_TIMESTAMP, DATEDIFF(minute,ACTIVE_TIMESTAMP,CLEARED_TIMESTAMP) as Downtime FROM ALERT_LOG WHERE displaypath='Kill Floor Alarms' and STATE_NAME='{Root Container.Dropdown 1.selectedStringValue}' and ACTIVE_TIMESTAMP>='{Root Container.Date Range.startDate}' and ACTIVE_TIMESTAMP<='{Root Container.Date Range.endDate}' order by ACTIVE_TIMESTAMP desc

But I can’t figure out how to display all of the alarms if “All” is selected in the dropdown menu. Is there a way I can enable/disable the and STATE_NAME=’{Root Container.Dropdown 1.selectedStringValue}’ part of the where clause if “All” is selected? I’m not really an SQL guru so I don’t know if there is an easy way of doing this or not. I’ve tried putting SELECT “All” as Null in on the dropdown box but that didn’t work so now I’m not sure what to do. Any ideas would be much appreciated, thanks!

Just add a dynamic property to the dropdown component called whereClause that is a string. Bind the new property to the following expression:if({Root Container.Dropdown 1.selectedStringValue} = 'All', "1=1", "STATE_NAME='" + {Root Container.Dropdown 1.selectedStringValue} + "'"Just use the whereClause in the SQL query:SELECT STATE_NAME, ACTIVE_TIMESTAMP, CLEARED_TIMESTAMP, DATEDIFF(minute,ACTIVE_TIMESTAMP,CLEARED_TIMESTAMP) as Downtime FROM ALERT_LOG WHERE displaypath='Kill Floor Alarms' and {Root Container.Dropdown 1.whereClause} and ACTIVE_TIMESTAMP>='{Root Container.Date Range.startDate}' and ACTIVE_TIMESTAMP<='{Root Container.Date Range.endDate}' order by ACTIVE_TIMESTAMP descThat way when All is selected the query goes AND 1=1 which brings back everything otherwise it filters it. Hope that helps.

Wow, that’s beautiful! I would have never thought of that, it worked great. Thanks!