>>Can you post the structure of the table(s) involved here to determine when category has subcategories?
>
>Category table
>
>Numero Primary key
>Title Character(20)
>NoCategory Category primary key
>
>So, basically, this is recursive inside the same table.
>
>So, an unlimited number of categories can have parents and so on.
>
>For most of them, Category.NoCategory is 0 so that denotes a parent. That is the highest hierarchy.
>
>Then, for those records having a value in Category.NoCategory, it means they are child records of the parent. The parent can also be a child of another parent.
So, do you want to count all subcategories or just top level subcategories? In the former case we're talking about recursive CTE.
If it's not broken, fix it until it is.
My Blog