Have you ever wanted to get a running total of all of the descendants of each tree node? This sort of thing is useful, especially if you don’t want to pull back an entire object graph just to compute the count of a child collection.
IF OBJECT_ID(‘tempdb..#categories’) IS NOT NULL
DROP TABLE #categories;
IF OBJECT_ID(‘tempdb..#product_categories’) IS [...]