with [CTE] as (
select * from [TheTable] c where c.[ParentId] = 1
union all
select * from [CTE] p, [TheTable] c where c.[ParentId] = p.[NodeId]
)
select * from [CTE]
More Related Contents:
- SQL query for parent-child chain
- Simulating group_concat MySQL function in Microsoft SQL Server 2005?
- How can I do an UPDATE statement with JOIN in SQL Server?
- The multi-part identifier could not be bound
- Fastest way to update 120 Million records
- Can a Check constraint relate to another table?
- Is it possible to select sql server data using column ordinal position
- How to find current transaction level?
- How to insert multiple records and get the identity value?
- basic recursive query on sqlite3?
- How can a LEFT OUTER JOIN return more records than exist in the left table?
- “select * from table” vs “select colA, colB, etc. from table” interesting behaviour in SQL Server 2005
- Dynamic SQL to generate column names?
- Extracting hours from a DateTime (SQL Server 2005)
- Column name or number of supplied values does not match table definition
- How to split string using delimiter char using T-SQL?
- SQL Server PIVOT perhaps?
- How to find consecutive rows based on the value of a column?
- Custom aggregate function (concat) in SQL Server
- How to escape square brackets inside square brackets for field name
- Average of multiple columns
- What is the internal representation of datetime in sql server?
- Use variable with TOP in select statement in SQL Server without making it dynamic [duplicate]
- how to increment integer Columns value by 1 in SQL
- How do I find the data directory for a SQL Server instance?
- Compare dates in T-SQL, ignoring the time part
- SQL: Aggregating strings together
- Distributed transaction error?
- SQL, How to Concatenate results?
- Determine what user created objects in SQL Server