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
 General SQL Server Forums
 New to SQL Server Programming
 Two values from the same table.

Author  Topic 

jwells
Starting Member

17 Posts

Posted - 2013-10-15 : 12:12:24
I have two tables, one is called InvTransfer and the WhsLoc. In InvTransfer I have two fields the hold the id to records WhsLoc. Tables look like:

InvTransfer:
ID
Created
OriginID
whsFromID
whsToID
Completed
Enabled

WhsLoc:
ID
Display
Name
Description
Type
Enabled

whsFrom and whsTo are joined to WhsLoc by it's ID.

I want to return * from InvTransfer but use the Name from WhsLoc table for each of whsFrom and whsTo. I know I can't simply join both fields to the WhsLoc table by he ID. How do I do this?



jwells
Starting Member

17 Posts

Posted - 2013-10-15 : 12:30:11
I was able to resolve it - thx

SELECT dbo.Employees.EmployeeID, dbo.Employees.EmplName, dbo.InvTransfer.ID, dbo.InvTransfer.Created, dbo.InvTransfer.OriginID,
dbo.InvTransfer.Completed, dbo.InvTransfer.Enabled, dbo.WhsLoc.Name AS FromName, WhsLoc_1.Name
FROM dbo.InvTransfer INNER JOIN
dbo.Employees ON dbo.InvTransfer.OriginID = dbo.Employees.ID INNER JOIN
dbo.WhsLoc ON dbo.InvTransfer.whsFrom = dbo.WhsLoc.ID INNER JOIN
dbo.WhsLoc WhsLoc_1 ON dbo.InvTransfer.whsTo = WhsLoc_1.ID
Go to Top of Page
   

- Advertisement -