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
 Transact-SQL (2000)
 Cursor Or While ?

Author  Topic 

fl0at
Starting Member

5 Posts

Posted - 2004-08-19 : 03:22:19
Having a table like this

did pid name haschild
1 0 Parent 0
2 1 Sub1 0
3 2 Sub2 1
5 1 Suba1 0
16 3 Suba2 1

I need to get this result
if did = 1
count the subs and get the deepest did having haschild = 1
And there can be more more deep in these subbing.
How can i find the given the subs of given did ?
Suppose when u reach subbest level there is haschild 1
Shall i use cursor or while loop ?
Any Ideas..?


samsekar
Constraint Violating Yak Guru

437 Posts

Posted - 2004-08-19 : 04:07:39
Can you please post the expected results?

- Sekar
Go to Top of Page

fl0at
Starting Member

5 Posts

Posted - 2004-08-19 : 05:21:44
quote:
Originally posted by samsekar

Can you please post the expected results?

- Sekar



Ok . Here is what i have in my

When i give a did to a stored proc it will make a list of all dids those haschilds are 1 and which all belong to main of that did. Like

Suppose i have these in table
did pid haschild
1 0 0
2 1 0
3 2 1
4 1 1
9 3 1
12 2 1
13 12 1
16 13 1

Need this result when i ask did = 2

did pid haschild
3 2 1
9 3 1
12 2 1
13 12 1
16 13 1

Go to Top of Page
   

- Advertisement -