recursive-cte

SQL Server: Select Parent-Child

Hi I have SQL Server 2008 with a table called ProductCategories designed like this: Id | Name | ParentId 71 PCs NULL 32 MACs NULL 3 Keyboard 1 9 Mouse 1 5 Screen 1 11 Keyboard 2 7 Mouse 2 8 Screen 2 I would like to select from this table, and get a result set like t...

Recursive CTE Problem

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...