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)
 Hierarchy

Author  Topic 

ladiaocb
Yak Posting Veteran

57 Posts

Posted - 2005-05-19 : 16:15:27
I have 2 tables that look like:

tbl1

orgid parentid
10 1
11 1
12 2
13 2

tbl2

orgid username
1 Bill
2 Steve
10 John
11 Larry
12 Joe
13 Mark

I want to return the following value:

Result:

Agent Supervisor
John Bill
Larry Bill
Joe Steve
Mark Steve

Any ideas?

Seventhnight
Master Smack Fu Yak Hacker

2878 Posts

Posted - 2005-05-19 : 16:35:52
Select Agent=B.username, Supervisor=C.username
From tbl1 A
Inner Join tbl2 B
On A.orgId = B.orgId
Inner Join tbl2 C
On A.parentId = C.orgId


Corey

Secret Service Agent: Mr. President, you're urinating on me.
President Lyndon Johnson: I know I am. It's my prerogative.
Go to Top of Page

ladiaocb
Yak Posting Veteran

57 Posts

Posted - 2005-05-19 : 16:46:59
Sweet! This worked great.
Go to Top of Page
   

- Advertisement -