I'll attempt solution here based on what I think you are trying to say. By the way, it really helps out everyone if you can supply the create table statements along with sample data and sample results.
create
table Categories(categoryID int,levelId int,
ParentCategoryID
int, Categoryname varchar(30),
CategoryDesc
varchar(30));
insert
into Categories(categoryID, levelId, ParentCategoryID,
CategoryName
, CategoryDesc)
Select
1,0,NULL,'Notebooks','Notebooks'
UNION
select
2,0,NULL,'Pencils','Pencils'
UNION
select
3,1,1,'Notebook accessories','Notebook accessories';
create
table Products(ProductID int, CategoryID int);
insert
into Products(ProductID, CategoryID)
select
10,1
union
select
20,1
union
select
30,1
union
select
40,2
union
select
50,2
union
select
60,3
union
select
70,3;
select
count(*) as ProdCount
from
Products p join Categories c
on
p.CategoryID = c.CategoryID
where
c.CategoryID = 1 or c.ParentCategoryID = 1