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)
 recursive queries

Author  Topic 

harshal_in
Aged Yak Warrior

633 Posts

Posted - 2004-07-13 : 02:25:06
I have a following structure

table A
userid ReferedBy
B A
C B

Table B
Userid compID
A Alpha
B self
C self


now the scenario is :
the user A is from the company "Alpha"
he introduces user B, who registers in the system his company bcomes "self",
now B inturn refers user C who also registers in the system and his company is now again "self".
Now I need to generate a report of number of users that have registered under one company, for eg.
for the company "Alpha" no of users becomes 2 since A refered to two users and both of them have registered.

I m stuck with the query.
thanks in advance...
regards,
Harshal

He is a fool for five minutes who asks ,
but who does not ask remains a fool for life!



http://www.sqldude.4t.com

derrickleggett
Pointy Haired Yak DBA

4184 Posts

Posted - 2004-07-13 : 08:05:28
So, in your example, do you want the results to be:

Alpha 2
self 2

-or-

Alpha 2
self 1

MeanOldDBA
derrickleggett@hotmail.com

When life gives you a lemon, fire the DBA.
Go to Top of Page

harshal_in
Aged Yak Warrior

633 Posts

Posted - 2004-07-13 : 08:22:39
quote:
Originally posted by derrickleggett

So, in your example, do you want the results to be:

Alpha 2
self 2

-or-

Alpha 2
self 1

MeanOldDBA
derrickleggett@hotmail.com

When life gives you a lemon, fire the DBA.



I want the count of users who are registered under the company "Alpha".
I think the best bet would be to add a column parentCompany to the table, still in that case i'll have to update the existing records ...

He is a fool for five minutes who asks ,
but who does not ask remains a fool for life!



http://www.sqldude.4t.com
Go to Top of Page
   

- Advertisement -