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 |
|
iamnavid
Starting Member
6 Posts |
Posted - 2006-06-06 : 04:05:08
|
| Hi,I've a table like this.id,title,subidand some records like,1,title1,02,title2,13,title3,14,title4,2Subid is a foreignkey to the same table ID column.I want to create something like thistitle1 > title2 > title4where my categoryid is 4.I need rows like this1,title12,title24,title4How could I do this? I need subcategories of title4. and subcategories of subcategorie of title 4 and ... |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
iamnavid
Starting Member
6 Posts |
Posted - 2006-06-06 : 04:19:23
|
| But i need an SQL string to return just these rows, and nothing else,I need the reverse job that this do. |
 |
|
|
jen
Master Smack Fu Yak Hacker
4110 Posts |
Posted - 2006-06-06 : 04:21:34
|
you need to provide the tables involved and their relationship to one another for us to help you build the tsql for that --------------------keeping it simple... |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
|
Kristen
Test
22859 Posts |
Posted - 2006-06-06 : 04:30:45
|
| Is there a reasonable, and finite, limit to the number of levels you need to refer back to?When we make breadcrumbs like this we just self-join the table to itself to get the parent, grand-parent ... data. We have a maximum of about 5 levels and it seems to work fine.Kristen |
 |
|
|
iamnavid
Starting Member
6 Posts |
Posted - 2006-06-06 : 04:34:42
|
| there is no minimum or maximum for these levels, may be just one level or even 10-20 levels, but i think it would not increase more than 3 or 4. |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2006-06-06 : 04:45:50
|
| Store an additional "path" column that you can query to get all ancestors in one "hit"?So your data would be:1,title1,0,NULL2,title2,1,00013,title3,1,00014,title4,2,00010002(Decision to be made whether you store "self"'s ID in the Path, or not. We don't to save some storage)Kristen |
 |
|
|
|
|
|
|
|