I tried both of the options above, but both returned all results, ignoring the inAppl selection completely. Just to make sure I'm being clear, inAppl will either result in 0 (if the user chooses All) or an internal varchar value called oid. When I add inAppl to the result set, I see the correct oid value for my inAppl selection of 'Core', but I get all results whether that results cra.application = Core's oid or some other oid.
Here is my procedure (with commented items removed):
select distinct(crp.primaryIdentifier) as CaseID,
crm.mainDescription as 'Description',
crm.mainStatus as Status,
dsam.applicationName
from coredata_read.caseRoot_primary crp
inner join coredata_read.caseRoot_main crm on crp.oid=crm.oid
inner join coredata_read.caseRoot_applications cra on crp.oid=cra.oid
inner join coredata_read.dictSoftwareApplication_masterRecord dsam on dsam.oid=cra.application
where (ifnull( if ( inAppl = 0, null, inAppl ), cra.application ) = cra.application or (inAppl = 0 and cra.application is null))
order by crp.primaryIdentifier ASC;
When I select the application of Core, I get 10047 results, many of which are for other applications.
In a MySQL client, I run the following query and I get the correct 3027 results for all Cases with the application of Core:
select distinct(crp.primaryIdentifier) as CaseID,
crm.mainDescription as 'Description',
crm.mainStatus as Status,
dsam.applicationName
from coredata_read.caseRoot_primary crp
inner join coredata_read.caseRoot_main crm on crp.oid=crm.oid
inner join coredata_read.caseRoot_applications cra on crp.oid=cra.oid
inner join coredata_read.dictSoftwareApplication_masterRecord dsam on dsam.oid=cra.application
where dsam.applicationName = 'Core'
order by crp.primaryIdentifier ASC;