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 |
|
Thiyagu_04
Starting Member
37 Posts |
Posted - 2010-03-23 : 02:38:45
|
| Following Shows my table stucture.I need to find who is eligible for grand children.ID NAME ParentID 1 First NULL2 Second NULL3 First101 14 First102 15 First201 36 First202 47 Second101 28 Second201 79 first301 5Thanks in advance |
|
|
Sachin.Nand
2937 Posts |
Posted - 2010-03-23 : 02:44:59
|
| Have look at recursive queries in BOL.PBUH |
 |
|
|
karthik_padbanaban
Constraint Violating Yak Guru
263 Posts |
|
|
Thiyagu_04
Starting Member
37 Posts |
Posted - 2010-03-23 : 08:46:13
|
| Thanks for the reply.Karthik by this how to find how many level of grand childrens they have.For egID Level1 3(this is No of level not children)2 23 2 4 15 16 0 7 18 0Like this i want is it possible using "WITH" |
 |
|
|
Thiyagu_04
Starting Member
37 Posts |
Posted - 2010-03-23 : 09:07:44
|
| Thanks guys i have found the solutioneg:with [CTE] (ID,Name,ParentID,Level,pid) as ( select ID,Name,ParentID,0,ID as pid from [Pa] c union all select c.ID ,c.Name,p.ParentID,(p.Level+1),p.pid from [CTE] p, [Pa] c where c.[ParentId] = p.[Id] ) select distinct pid from [CTE] where Level=2 order by pid |
 |
|
|
|
|
|
|
|