November 28, 2008 at 12:25 pm
I have a Employee Table with SupervisorID which shows the Supervisor Employee number
and I want to show Supervisor Name from the EmployeeID and Employee field.
SELECT EmployeeID, FirstName+' '+LastName AS Employee,
SupervisorID, SiteID, HireDate
FROM dbo.Employee
November 28, 2008 at 12:31 pm
Here is one way to do it:
SELECT EmployeeID
, FirstName+' '+LastName AS Employee
, (Select s.FirstName+' '+s.LastName
From dbo.Employee s
Where s.EmployeeID = e.SupervisorID) as Supervisor
, SiteID
, HireDate
FROM dbo.Employee e
[font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
Proactive Performance Solutions, Inc. [/font][font="Verdana"] "Performance is our middle name."[/font]
November 28, 2008 at 1:07 pm
Here's another
SELECT e.EmployeeID,
e.FirstName + ' ' + e.LastName AS Employee,
s.FirstName + ' ' + s.LastName as Supervisor,
e.SiteID,
e.HireDate
FROM dbo.Employee e
LEFT OUTER JOIN dbo.Employee s ON e.SupervisorID = s.EmployeeID
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
November 28, 2008 at 1:27 pm
😀 Thank You it worked
I appricate the help...
November 28, 2008 at 1:30 pm
Glad we could help.
[font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
Proactive Performance Solutions, Inc. [/font][font="Verdana"] "Performance is our middle name."[/font]
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply