Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help with SQL select within Select Find manager name using a person manager ID number

Status
Not open for further replies.

leo57

Programmer
Oct 28, 2013
33
0
0
US
I want to use a one liner to get the Managers name along with the employees name. the Managers ID is txtManagerEnterpriseID
this T-SQL returns a NULL for Manager name right now.
can someone help me figure this out?
Code:
Select txtEnterpriseID,txtGivenname, txtSurname, txtCity ,txtManagerEnterpriseID ,
([highlight #FCE94F]Select (txtGivenname + ' ' + txtSurname)  from VLDAP Where
txtEnterpriseID =txtManagerEnterpriseID) AS Managername[/highlight]
from VLDAP
Where txtGivenname like 'st%'
And txtSurname like 'Cornell'

TIA

 
Try this:

Code:
Select txtEnterpriseID,
       txtGivenname, 
	   txtSurname, 
	   txtCity ,
	   txtManagerEnterpriseID ,
       (
	      Select (txtGivenname + ' ' + txtSurname)  
		  from   VLDAP As Employee
		  Where  Employee.txtEnterpriseID =txtManagerEnterpriseID
       ) AS Managername
from   VLDAP
Where  txtGivenname like 'st%'
       And txtSurname like 'Cornell'

If this works for you, and you want me to explain it, please let me know.

-George
Microsoft SQL Server MVP
My Blogs
SQLCop
twitter
"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
If either txtGivenname or txtSurname are NULL, then the result is NULL. Try something like ...

Code:
Select txtEnterpriseID,txtGivenname, txtSurname, txtCity ,txtManagerEnterpriseID ,
(Select (IsNull(txtGivenname + ' ','') + IsNull(txtSurname,''))  from VLDAP Where
txtEnterpriseID =txtManagerEnterpriseID) AS Managername
from VLDAP
Where txtGivenname like 'st%'
And txtSurname like 'Cornell'

--JD
"Behold! As a wild ass in the desert go forth I to my work."
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top