I have a table that is structured in the following manner that we have imported from another source into SQL Server:
| Tier 0 | Tier 1 | Tier 2 | Tier 3 |
|---|---|---|---|
| AA;AB;BB | T1A;T1B | T1A2A;T1A2B;T1B2A | T1A2A3A;T1A2B3A;T1B2A3Z |
| AAA;CC | T1A;T1C | T1A2A;T1A2C;T1C2F | T1A2A3A;T1A2B3A;T1C2F3G |
| AA;ZZ | T1Z | T1Z2A;T1Z2C;T1Z2F | T1Z2A3A;T1Z2B3A;T1Z2F3G |
This data is structured in such a way that each subsequent column is like a child of the previous one. Also, each item is divided by semi-colon.
Is there a way to get a list of the subsequent tier, based on a search. Using the above table as an example, if I want to get a list of all possible tier 1, where the tier 0 contains "AA", it will return this result:
| Tier 1 |
|---|
| T1A;T1B |
| T1Z |
But the user could also select multiple Tier 0 items. If he would search by "AA" together with "BB" the table would then return
| Tier 1 |
|---|
| T1A;T1B |
Is it possible to achieve this with a SELECT statement?
Unfortunately, stored procedures and functions are not options I have available.
We didn't have the option to restructure on import as our client has reports that use this structure, so we have to reverse engineer the data as is. While it would be possible now, we have more than a million rows. Manually setting this hierarchy would not be feasible.