This isn't code for you just an example of how to do something like this ... This code will create a tree ... sort of ... it just gets all children under a certain node ... in this instance it returns all children of the root nodes... if you structure is something like this this code should be pretty easy for you to manipulate for your needs.declare @tree table (parent_id int, child_id int, value varchar(256), level int)declare @level intset @level = 0insert into @tree (parent_id, child_id, value, level) select null, catalog_category_id, category_name, @level from catalog_categories where parent_id is nullwhile exists(select catalog_category_id from catalog_categories where parent_id in (select child_id from @tree) and catalog_category_id not in (select child_id from @tree)) begin set @level = @level + 1 insert into @tree (parent_id, child_id, value, level) select parent_id, catalog_category_id, category_name, @level from catalog_categories where parent_id in (select child_id from @tree) and catalog_category_id not in (select child_id from @tree) end