views:

48

answers:

0

I have the following hierachy

 Category

   SubCategory

     sub-SubCategory

I have two tables for this:-

Category(CategoryID,CatName,CatDesc) CategoryID is primaryKey

SubCategory(SubCategoryID,SubCategoryName,SubCategoryDesc,CategoryID,ParentSubCategoryID)

SubCategoryID is primarykey.

CategoryID is foreignKey to CategoryID of Category table.

ParentSubCategoryID is foreign key to SubCategoryID ( this forms a self-referential join)

To get sub-subcategory under subcategory I put the SubCategoryID in ParentSubCategoryID field

I want a query which returns a Category,subCategory,sub-subCategory in a hierachy.I was not able to achieve it using for xml auto in sql server.

Even i didnot find a way out using CTE.

Please suggest some workaround.