0

I am trying to run the following SQL query in access VBA and I am getting a join error.

I can't seem to figure out what the problem is. I'm sure there's something obvious I am just overlooking.

SELECT a.LateDate, a.LateAgent, a.LateTime, b.PBXID,
       (b.FirstName + ' ' + b.Surname) as FullName
from tblLateLog a
    INNER Join tblAgents b on a.LateAgent = FullName
3
  • Can you add on your question what the error is? Commented Mar 2, 2016 at 11:30
  • You can't use column aliases in the ON clause. Do ON a.LateAgent = (b.FirstName + ' ' + b.Surname). Commented Mar 2, 2016 at 11:31
  • Please remove the excel-vba tag as this isn't anything to do with Excel Commented Mar 2, 2016 at 11:40

2 Answers 2

2

You can't use column aliases in the ON clause:

SELECT a.LateDate, a.LateAgent, a.LateTime, b.PBXID,
       (b.FirstName + ' ' + b.Surname) as FullName
from tblLateLog a
    INNER Join tblAgents b ON a.LateAgent = (b.FirstName + ' ' + b.Surname)
Sign up to request clarification or add additional context in comments.

Comments

0

You can't use an alias in the same context of your query to do a join. Do as this:

SELECT a.LateDate, a.LateAgent, a.LateTime, b.PBXID,
       (b.FirstName + ' ' + b.Surname) as FullName
  FROM tblLateLog a
     INNER Join tblAgents b on a.LateAgent = (b.FirstName + ' ' + b.Surname)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.