Here is a better format for your DDL and some DMLCREATE TABLE #Rollups([RollupID] [bigint] IDENTITY(1,1) NOT NULL,[ItemID] [bigint] NOT NULL,[ItemLeft] [bigint] NULL,[ItemRight] [bigint] NULL)CREATE TABLE #Items([ItemID] [bigint] IDENTITY(1,1) NOT NULL,[Name] [nvarchar](50) NOT NULL)insert into #Items ([Name])select 'All Products'union all select 'All Food'union all select 'All Drinks'union all select 'Chicken'union all select 'Nachos'union all select 'Steak'union all select 'Water'union all select 'Beer'union all select 'Juice'insert into #Rollups(ItemID,ItemLeft,ItemRight)select 1 ,1 ,18union all select 2, 2, 9union all select 3 ,10, 17union all select 4 ,3, 4union all select 5 ,5, 6union all select 6, 7, 8union all select 7, 11, 12union all select 8 ,13, 14union all select 9 ,15, 16select * from #itemsselect * from #Rollups
Now I just have to do a search on Hierarchical data and find a link for you, since i stink at it.http://weblogs.sqlteam.com/jeffs/archive/2008/05/13/question-needed-not-answer.aspxHow to ask: http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspxFor ultra basic questions, follow these links.http://www.sql-tutorial.net/ http://www.firstsql.com/tutor.htm http://www.w3schools.com/sql/default.asp