I'm trying to implement a front end for a reporting solution which is security dependent. The user has 12 levels of nested criteria to select from, the value of each affects all of the values below.
So the criteria selection on the page (each is a dropdown) looks something like this:
Criteria 1
Criteria 2
...
Criteria 12
There is a Security table that holds the values that are available to each user which has the following structure:
EmployeeID | Criteria_1_valid_Value | C2_valid_Value | ... | C12_valid_Value
x0001 | c1 | c2 | ... | c12
and each Employee will have one or (many) more rows in this table. Think of it as a flattened tree, with Criteria1 as the root node.
Based on keys, changing Criteria 1 will affect the values that are visible in Criteria 2 through 12. In the same way, changing the value in Criteria 2 affects the values available in Criteria 3 through Criteria 12. At each level, there is an option to select 'All Values,' which is represented by a space internally, for lookups. So I need a representation in the lookup table/view which takes into account that there may be a space at one or many levels.
Where I'm struggling is with finding a way to build the lookup view/table for each Criteria field using sql without having to resort to hardcoding.
For example, to build the lookup for criteria 2 the sql might look like this:
select EmployeeID, Criteria1, Criteria2
from Security
Union
select EmployeeID, ' ', Criteria2
from Security
Union
select EmployeeID, Criteria1, ' '
from Security
UNION
select EmployeeID, ' ', ' '
from Security
And so on. Unfortunately, of course, with 12 levels, the last works out to 2^12 unions, which frankly smells.
I've tried building a table for each level in batch, committing after each, then using the previous table joined to the Security table to build the next with a single UNION in each, but I can't seem to get the joins to work properly with the spaces.
I don't know if I'm overthinking this or completely missing something, but I feel like there has to be a simpler solution.
EDIT: This is on Oracle and I'm working with an ERP product as the underlying technology.
EDIT2: Thanks for the input everyone. I got the joins eorking correctly using joins like in the example proc from @Alex Poole below:
and (v_Criteria_1 = ' ' or Criteria_1_valid_Value = v_Criteria_1)
I was missing the v_Criteria_1 = ' ' or
.
So I've got the tables loaded correctly (enough) now. This is turning into a tuning/optimization exercise. I'm going to look at the proc from @Alex Poole and the artithmetic approach of @JD_55 which I think might be very quick.