I have 2 tables: Employees(EmployeeID, FirstName, LastName),
EmployeeApplication(CreatedByID, EmployeeID,Date1, Date2, Content...)
I need to create stored procedure that will return employee First and
Last names (plus some other columns) instead *both* ID's in
EmployeeApplication.
I know how to do it with only one - I am using simple join, but with
two I have no idea...
Can anyone help me ?
Richard...Hi Richard,
You simply add one more join for the Employees table to get the names for
the other ID, something like this:
SELECT A.EmployeeID,
E.FirstName AS emp_fname,
E.LastName AS emp_lname,
A.CreatedByID,
C.FirstName AS creator_fname,
C.LastName AS creator_lname,
A.Date1,
A.Date2,
A.Content
FROM EmployeeApplication AS A
JOIN Employees AS E
ON A.EmployeeID = E.EmployeeID
JOIN Employees AS C
ON A.CreatedByID = C.EmployeeID
This is assuming the CreatedByID column is referring to the EmployeeID
column from the Employees table. If that is not the case then you have to
replace the Employees table in the second join with the appropriate table
and the appropriate column for the join.
HTH,
Plamen Ratchev
http://www.SQLStudio.com
No comments:
Post a Comment