Query Help

knownheroknownhero Member Posts: 450
Im having trouble mergin 3 tables into a query. It works with 2 fine but when I try add the Persons email address into it, it fails see below:
SELECT HumanResources.EmployeePayHistory.BusinessEntityID, Rate, HumanResources.Employee.LoginID, Person.EmailAddress.EmailAddress, JobTitle

From HumanResources.EmployeePayHistory, Person.EmailAddress.EmailAddress

INNER JOIN HumanResources.Employee,Person.EmailAddress.EmailAddress

ON HumanResources.EmployeePayHistory.BusinessEntityID = HumanResources.Employee.BusinessEntityID and HumanResources.Employee.BusinessEntityID = Person.EmailAddress.BusinessEntityID

ORDER BY BusinessEntityID DESC;


ERROR:
Msg 102, Level 15, State 1, Line 5
Incorrect syntax near ','.

Fixed:
SELECT HumanResources.Employee.BusinessEntityID, HumanResources.Employee.LoginID, Person.EmailAddress.EmailAddress, HumanResources.EmployeePayHistory.Rate
                      
FROM Person.EmailAddress INNER JOIN HumanResources.Employee ON Person.EmailAddress.BusinessEntityID = HumanResources.Employee.BusinessEntityID 

INNER JOIN HumanResources.EmployeePayHistory ON HumanResources.Employee.BusinessEntityID = HumanResources.EmployeePayHistory.BusinessEntityID

ORDER BY BusinessEntityID DESC;
70-410 [x] 70-411 [x] 70-462[x] 70-331[x] 70-332[x]
MCSE - SharePoint 2013 :thumbup:

Road map 2017: JavaScript and modern web development

Comments

  • RobertKaucherRobertKaucher Member Posts: 4,298 ■■■■■■■■■■
    I just wanted to mention it is a very good practice to post your own answer as it really does add value to TE as a resource for others.

    Could you edit your posts and format them as code, though?
  • knownheroknownhero Member Posts: 450
    Hey Robert,

    If I was honest I used a view to create the T-SQL I needed :D

    By code how do you mean isn't how it already code? Sorry if that sounds stupid.

    Regards.
    70-410 [x] 70-411 [x] 70-462[x] 70-331[x] 70-332[x]
    MCSE - SharePoint 2013 :thumbup:

    Road map 2017: JavaScript and modern web development

  • RobertKaucherRobertKaucher Member Posts: 4,298 ■■■■■■■■■■
    There is a format option like [ QUOTE ] but it is [ CODE ] so if you wrap your code in [ CODE ] [ /CODE ] (no spaces) and tab it out it's easier to read. Here is an example:
    SELECT  Column1
           ,Column2
           ,Column3
    FROM TableName
    WHERE Column1 = 'Some Text'
    
  • knownheroknownhero Member Posts: 450
    Ah! Okay got you! thanks for the tip I will keep that in mind.
    70-410 [x] 70-411 [x] 70-462[x] 70-331[x] 70-332[x]
    MCSE - SharePoint 2013 :thumbup:

    Road map 2017: JavaScript and modern web development

Sign In or Register to comment.