I have a recursive table in which each record has an ID and a PARENTID. PARENTID points to a different ID in the same table. Is there a way in SQL Server to select an entire "tree" in one statement? I could write a recursive function to jump from a parent to all the children, but I'd like a way to do it in one query.
In Oracle, it would look like this:
select
id,
parentid,
nodename
from
MY_SCHEMA.MY_TABLE
connect by nocycle prior parentid = id
start with id = :starting_id_number
order by
id
What would the SQL Server equivalent be?