;With cte As (Select e.entryID, e.bOpen, e.nextEntryID, e.entryID As OriginalentryID From entries e Where e.bOpen = 1 And e.nextEntryID Is Not Null Union All Select e.entryID, e.bOpen, e.nextEntryID, c.OriginalentryID From cte c Inner Join entries e On e.entryID = c.nextEntryID) Select c.entryID, c.OriginalentryID From cte c Where bOpen = 0;
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)