Recursive CTE Problem
- by Chris
Hi,
I am trying to use a recursive CTE in SQL Server to build up a predicate formula from a table containing the underlying tree structure.
For example, my table looks like:
--------------------------
Id Operator/Val ParentId
--------------------------
1. 'OR' NULL
2. 'AND' 1
3. 'AND' 1
4. '' 2
5. 'a' 4
6. 'alpha' 4
: : :
--------------------------
which represents ((a alpha) AND (b beta)) OR ((c gamma) AND (a < delta)).
ParentId is a reference to the Id in the same table of the parent node.
I want to write a query which will build up this string from the table. Is it possible?
Thanks