Recursive CTE Problem

Posted by Chris on Stack Overflow See other posts from Stack Overflow or by Chris
Published on 2010-04-08T16:09:59Z Indexed on 2010/04/08 16:13 UTC
Read the original article Hit count: 539

Filed under:
|

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

© Stack Overflow or respective owner

Related posts about recursive-cte

Related posts about sql-server