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.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Parent Child Relationships

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2003-11-03 : 07:46:02
Donnie Carvajal writes "I have a parent child relationship using 1 table:

TABLE

ID int
Name VARCHAR(50)
ParentID int

Where the ID and ParentID are related.

I understand how to get the full tree using a recursive join. The problem that I am having has to do with pin pointing a node. Lets say I want to get all of the child nodes of parent with ID 1. Is there a way to gather this information using 1 query.

Thanks."

Stoad
Freaky Yak Linguist

1983 Posts

Posted - 2003-11-03 : 09:50:24
create table #rr (p varchar(8), c varchar(8))
insert into #rr
select 'a', 'b' union all
select 'a', 'c' union all
select 'a', 'd' union all
select 'b', 'e' union all
select 'k', 'z' union all
select 'p', 'q' union all
select 'b', 'f'
go
declare @s varchar(8000) set @s='a'
select @s=@s+case when charindex(p, @s)>0 then c else '' end
from #rr

print 'Papa and his children: ' + @s

drop table #rr
Go to Top of Page
   

- Advertisement -