Thank you all! Indeed there are some issues with cycles in the data. It was a combination of Ramireddy's response and Erland that helped me solve this.
-->
Example
CategoryId | ParentCategoryId10 3
3 10
The statement terminated. The maximum recursion 32767 has been exhausted before statement completion.