Couldn't you just call a stored procedure to loop round grabbing each sub level of data and storing the set of task ids in a work table. You'd then just make all your joins against the work table. That way you can encapsulate all the multiple level stuff into one stored proc and the rest of the SQL code you write would be pretty simple. Another smaller benefit would be that it is infinitely scaling.