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 2005 Forums
 SSIS and Import/Export (2005)
 Recursive Query

Author  Topic 

Dev@nlkss

134 Posts

Posted - 2009-03-23 : 06:54:00
Hi all
I have a table with follwoing data.

ID - ParentID - Name
1 - 0 - A
2 - 1 - B
3 - 1 - C
4 - 2 - D

i.e A is the root level item and it has children of B,C.
I have to display as follows
A->B
A->C
B->D

How can i display as above.
thanks in advance.

$atya.

Love All Serve All.

ra.shinde
Posting Yak Master

103 Posts

Posted - 2009-03-23 : 07:09:46
DECLARE @TAB1 TABLE
(
ID int,ParentID int,Name varchar(10)
)
INSERT INTO @TAB1
select 1,0, 'A'
union
select 2,1,'B'
union
SELECT 3,1,'C'
union
select 4,2,'D'

select parent.name,child.name
from
@TAB1 parent
inner join @TAB1 child on child.ParentID = parent.id

Rahul Shinde
Go to Top of Page
   

- Advertisement -