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 2008 Forums
 Transact-SQL (2008)
 Two names in one query

Author  Topic 

Garnett
Starting Member

2 Posts

Posted - 2010-06-16 : 13:11:25
I have a table called Users, and another table called Transfers. In the Transfers table I have two user id fields specifying the person who did the transfer and the person who received it. How can I get both user names for a transfer eg. transferDate, FullNameOfPersonWhoDidTransfer, FullNameOfPersonWhoReceivedTransfer

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2010-06-16 : 13:47:08
Join Users table twice like
select a.transferDate
,b.Name as [FullNameOfPersonWhoDidTransfer]
,c.Name as [FullNameOfPersonWhoReceivedTransfer]
from Transfers a
inner join Users b on b.NameID = a.NameIDofPersonWhoDidTransfer
inner join Users c on c.NameID = a.NameIDOfPersonWhoReceivedTransfer
Go to Top of Page

Garnett
Starting Member

2 Posts

Posted - 2010-06-16 : 14:14:56
Works perfectly, how did I not think of that :)
Go to Top of Page

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2010-06-16 : 14:47:58
. Well..you won't forget it from now.
Go to Top of Page
   

- Advertisement -