Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
udelojf
Starting Member
2 Posts |
Posted - 2007-03-16 : 10:47:12
|
| My Table StructureCategory_ID Number Parent_ID Number <----Category_ID reports to this columCategory_Name Varchar....MY QUERY <---I replaced the query above with my data=============================WITH Hierarchy(Category_ID, Category_Name, Parent_ID, HLevel)AS(SELECT Category_ID, Category_Name, Parent_ID, 0 as HLevel FROM Dir_CategoriesUNION ALLSELECT SubCategory.Category_ID, SubCategory.Category_Name,SubCategory.Parent_ID,HLevel + 1FROM Dir_Categories SubCategoryINNER JOIN Hierarchy ParentCategoryON SubCategory.Parent_ID = ParentCategory.Category_ID )SELECT Category_ID, Category_Name = Replicate('__', HLevel) + Category_Name, Parent_ID,HLevelFROM HierarchyMy OUTPUT============All the categories under reporting to Parent_ID 0 or continuous, then the ones reporting to 1 and so fourth. Subcategories are not showing within their main categories. I AM GOING NUTS WITH THIS.Can you help me please? |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-03-16 : 10:48:24
|
| I think you must have a WHERE clause in the first SELECT within CTE, getting only parent categories.Peter LarssonHelsingborg, Sweden |
 |
|
|
udelojf
Starting Member
2 Posts |
Posted - 2007-03-16 : 14:49:47
|
| Just tried that, doesnt work. Thanks anyway. Any other suggestion? |
 |
|
|
|
|
|
|
|