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
 Transact-SQL (2005)
 Query

Author  Topic 

balagangadharan
Starting Member

5 Posts

Posted - 2008-08-08 : 06:26:36
Hello All
im developing an application using VS2005(C#)
i have Database (SQL 2005) and i have table like this


Rid IntroID

1 1

2 1

3 1

4 2

5 2

6 2

7 3

8 3

9 3

10 4

11 4

12 5



These are the two fields in my table



Now in want to get the Rid by passing the IntroID



Here is the Query for this



Select rid from tbl_tree where IntroID= 1



This query returns three rows.



I need query that returns the child datas



When I pass Introid as 1, the query returns first three rows as

2

3

4



Now the query should return the datas for Introid 2,3,4 like wise for all



How can I do this?

Please help me

Thanks in Advance

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-08-08 : 06:29:52
quote:
I need query that returns the child datas

What is child datas ?

quote:
When I pass Introid as 1, the query returns first three rows as

2

3

4

How did the 2, 3, 4 comes from ? From the provided sample data, for IntroID = 1, the RID is 1, 2, 3


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

Go to Top of Page

balagangadharan
Starting Member

5 Posts

Posted - 2008-08-08 : 06:41:01
Hi
Thanks For Replying

RID INTROID
1 1
2 1
3 1
4 2
5 2
6 3
7 3

These are the data's i have in my table

The Query i used to select RID from Table where INTROID =1 is

Select rid from tbl_tree where IntroID= 1

so it returns three rows as

RID
1
2
3

Now Upline for 2 and 3 is 1
downline for 2 is are 4 and 5
downline for 2 is are 6 and 7

so INTROID 1 is master for 2,3,4,5,6,7

so when i pass INTROID as 1, it should
return total count for downline as 6
return total count for upline as 0

so when i pass INTROID as 2, it should
return total count for downline as 2
return total count for upline as 1

like wise for all

how to do this please help me

Thanks in Advacnce

Reagards
Balagangadharan
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-08-08 : 06:48:15
search for Tree & Hierarchy in the site

also search for recursive CTE as you are using SQL 2005


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

Go to Top of Page
   

- Advertisement -