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 |
|
mr_dayal
Starting Member
37 Posts |
Posted - 2008-09-08 : 07:03:35
|
| I have a table category_master having definition like this..cat_id bigint parent_id bigint cat_name varchar(50) date_added datetime date_modified datetime There r few data in this table.cat_id parent_id cat_name3 0 COMPUTERS5 0 PRINTERS7 3 FLASH MEMORY8 3 CD/DVD DRIVES9 8 EXTERNAL CD/DVD DRIVES12 0 APPERALS13 12 SHIRTS15 0 CONSUMER DURABLES16 15 A/C17 0 CHOCOLATES28 12 LEATHER GOODS29 0 CHILDREN30 29 CHILDREN SHIRTS31 29 CHILDREN T-SHIRTS32 29 TOYS33 7 MEMORY34 15 MOBILE35 34 CAMERA MOBILE36 12 PEN37 13 MEN49 8 INTERNAL CD/DVD DRIVESnow , If I select Computers , All the categories lying under it should be listed.Like If I select 'COMPUTERS' First 'CD/DVD DRIVES' and FLASH MEMORY Should be selected and then 'INTERNAL CD/DVD DRIVES' and 'EXTERNAL CD/DVD DRIVES'should be selected since they r under 'CD/DVD DRIVES'category which is again under the main category of 'computers'.In short If I select computers , all the sub categories at all the levels should be selected.(CD/DVD DRIVES', 'FLASH MEMORY','EXTERNAL CD/DVD DRIVES','INTERNAL CD/DVD DRIVES')Mr Dayal |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2008-09-08 : 09:47:24
|
| What version of SQL Server are you using?Also, please provide a specific example of how you would like the results to be returned. i.e., exactly what rows/columns you are looking for.- Jeffhttp://weblogs.sqlteam.com/JeffS |
 |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2008-09-08 : 12:20:27
|
| If you are using 2005 or 2008 look in BOL for Recursive CTEs. You can also do a search on the formus here and get some other examples. |
 |
|
|
jhocutt
Constraint Violating Yak Guru
385 Posts |
Posted - 2008-09-08 : 12:30:31
|
| http://www.sitepoint.com/article/hierarchical-data-database/"God does not play dice" -- Albert Einstein"Not only does God play dice, but he sometimes throws them where they cannot be seen." -- Stephen Hawking |
 |
|
|
|
|
|