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 2008 Forums
 Transact-SQL (2008)
 how to do this result output

Author  Topic 

vinothrao84
Starting Member

21 Posts

Posted - 2009-07-26 : 23:52:22
hi,

Below is my table.

Parent ID.......ID.......Name
NULL..........10001.....Region1
NULL..........10002.....Region2
NULL..........10003.....Region3
10001.........501.......Test1
10001.........502.......Test2
10002.........503.......Test3
10002.........504.......Test4
10003.........505.......Test5
10003.........506.......Test6
501...........507.......Test7
501...........508.......Test8
502...........509.......Test9
502...........510.......Test10

I want the output to be the following.

ParentID.......ID.......Name
10001..........501......Test1
10001..........502......Test2
501............512......Armenia
501............536......Brunei
NULL...........10001....Region1

Based on where clause for ID = '10001'

Pls help. I can't figure out on how to add the last entry of "NULL......10001....Region1"

Thx.

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-07-26 : 23:56:53
can you explain your logic or what are you trying to do here ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

vinothrao84
Starting Member

21 Posts

Posted - 2009-07-27 : 00:04:54
quote:
Originally posted by khtan

can you explain your logic or what are you trying to do here ?


KH
[spoiler]Time is always against us[/spoiler]





hi,

thx for the reply.

actually i need the output that way in order my asp.net treeview to work properly.

thx.
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-07-27 : 00:23:17
search this site (use the SEARCH on the TOP RIGHT corner) for recursive cte


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -