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)
 relationship question

Author  Topic 

attackmonkey
Starting Member

19 Posts

Posted - 2002-08-14 : 05:44:57
I have a database table of users, which has the user's id, which is the primary key, several typical user details fields and the user id of the user that created the user account. Now I need to be able to list off all users that a user has created, as well as all the users that they have created as well (basically all users below them inthe chain). What would be the best way to pull this out as a single select list. I can do it using a recursive function in asp to sort all of teh users and display in a nice tree, but I also need to be able to just pull a complete list out as well, and I can't for the life of me figure out the best (or any) way of doing it.

Any help greatly appreciated!

:)

Tim.


nr
SQLTeam MVY

12543 Posts

Posted - 2002-08-14 : 05:50:45
You have a tree on which a lot has ben written on this site

try something like
create table #a(id int)
insert #a select @userid

while @@rowcount > 0
insert #a select distinct userid
from tbl, #a
where tbl.createduser = #a.userid
and not exists (select * from #a where tbl.userID = #a.ID)

select * from #a
drop table #a


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -