Skip to main content
OutSystems

How to filter an advanced query with a Boolean parameter

Question

I need a SQL query with a Boolean parameter. I want to add a condition if the parameter is true.

For example, I want to add the condition following condition if HideClosedProjects is true.

{VW_F_CAPEX_TRNS}.[PROJECT_STATUS] != ‘Closed’

Answer

A Boolean value becomes 0 or 1 in the database.

For the example, modify the SQL query by adding the input parameter HideClosedProjects with type Boolean. Then, add a condition to the query as shown below:

SELECT (...)
FROM (...)
WHERE
    (HideClosedProjects = 0 or
        {VW_F_CAPEX_TRNS}.[PROJECT_STATUS] != ‘Closed’)

If HideClosedProjects is false, the SQL engine never evaluates the second part of the condition.