A recursive or tree style table is a table which could have a Foreign key to itself. In my situation I have a product categories table. The one belowTB_Categories----------------catId INT IDENTITYcatParentId INTcatName nvarchar(50)
Let us suppose that it has the following dataTB_Categories------------------------------------------------catId |catParentId |catName------------------------------------------------1 |0 |Root 12 |0 |Root 23 |1 |SubRoot 1.14 |2 |SubRoot 2.15 |1 |SubRoot 1.26 |0 |Root 37 |2 |SubRoot 2.28 |1 |SubRoot 1.39 |3 |SubRoot 1.1.110 |3 |SubRoot 1.1.211 |6 |SubRoot 3.112 |11 |SubRoot 3.1.113 |11 |SubRoot 3.1.2------------------------------------------------
You can represent the data in the above table as a treeI supppose you get the idea.My problem is this...Let's say i am in category 9 |3 |SubRoot 1.1.2I want to build an sql statement which will return all the categories above it AND/OR including the category i am in. i want a T-Sql which will return------------------------------------------------1 |0 |Root 13 |1 |SubRoot 1.19 |3 |SubRoot 1.1.2------------------------------------------------You may wonder why i need this...i want to be able to say in the asp pageyou are here:Root 1>Subroot 1.1>Subroot1.1.2Any suggestions????