Results 1 to 11 of 11
  1. #1
    craigh is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Sep 2014
    Posts
    5

    Unhappy SQL error

    I keep getting a sql error (missing operator) with this. what am I doing wrong?

    SELECT u.[Part Description], u.[Part Number], a.[Last Name], a.[First Name]


    FROM Uniforms u INNER JOIN uniform_assignments ua
    ON u.uniformID = ua.uniformID JOIN [Band Addresses] a
    ON ua.studentID = a.StudentID
    WHERE (((ua.[Date Assigned]) Is Not Null) AND ((ua.[Date Returned]) Is Null));

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,549
    Sorry, but it looks ok but I dont see the reason for alias' on the join fields.
    Did you try without the alias'.

  3. #3
    craigh is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Sep 2014
    Posts
    5
    Hi ranman256 - thank you for your reply.

    I did try it without the alias' first and got the same error. :-(

    I used the alias' to try to simplify the query a bit (at least make it more readable).

    The full error is:

    Syntax error (missing operator) in query expression 'u.uniformID = ua.uniformID JOIN [Band Addresses] a
    ON ua.studentID = a.StudentI'

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,644
    You are building this in query designer? Not VBA?

    Could try:
    AS a
    AS u
    AS ua

    Access usually fills in the AS keyword if neglected.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    I don't think you can use just JOIN by itself - you have to specify INNER, LEFT, RIGHT, or FULL JOIN.

    John

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,644
    Doh! good eyes John.

    If building in query designer, that should not happen. Build in designer then switch to SQL View to get statement if you want to see the syntax to use in VBA.

    I've never seen FULL used.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    John is right, plus Access adds parenthesis after the keyword FROM:
    Code:
    SELECT u.[Part Description], u.[Part Number], a.[Last Name], a.[First Name]
    FROM (Uniforms u INNER JOIN uniform_assignments ua ON u.uniformID = ua.uniformID) 
    INNER JOIN [Band Addresses] a
    ON ua.studentID = a.StudentID
    WHERE (((ua.[Date Assigned]) Is Not Null) AND ((ua.[Date Returned]) Is Null));

  8. #8
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,644
    Access adds more parens than needed. Sometimes very annoying.

    I do wonder if INNER join will produce desired output.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  9. #9
    craigh is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Sep 2014
    Posts
    5
    Quote Originally Posted by ssanfu View Post
    John is right, plus Access adds parenthesis after the keyword FROM:
    Code:
    SELECT u.[Part Description], u.[Part Number], a.[Last Name], a.[First Name]
    FROM (Uniforms u INNER JOIN uniform_assignments ua ON u.uniformID = ua.uniformID) 
    INNER JOIN [Band Addresses] a
    ON ua.studentID = a.StudentID
    WHERE (((ua.[Date Assigned]) Is Not Null) AND ((ua.[Date Returned]) Is Null));
    This code works! Thanks so much for your help.

    Quote Originally Posted by June7 View Post
    I do wonder if INNER join will produce desired output.


    You are exactly right. I'm not getting what I hoped


    What I am trying to do is get a list of ALL uniforms. Then if the uniform is currently assigned, show the person it is assigned to. The assignments are based on a date range (hence the WHERE statement). But the current WHERE is excluding any uniform that is currently unassigned. I can get just the unassigned uniforms with a query like this:

    Code:
    SELECT Uniforms.[Part Description], Uniforms.size, Uniforms.[Part Number]
    FROM Uniforms
    WHERE ((((Uniforms.uniformID) Not In (select uniformID from uniform_assignments where [Date Returned] is null)));
    Does anyone see an easy way of combining these to produce the desired result? (I originally was trying to use a LEFT JOIN but didn't get that to work either )

  10. #10
    craigh is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Sep 2014
    Posts
    5
    I tried using the Query Designer (I think that's what its called - shows tables at the top and fields below) with the successful query above and just dbl clicked on the relation between Uniforms and uniform_assignments and changed it to a LEFT JOIN. I get an error then about ambiguous query.

    Code:
    SELECT u.[Part Description], u.[Part Number], a.[Last Name], a.[First Name]
    FROM (Uniforms AS u LEFT JOIN uniform_assignments AS ua ON u.uniformID = ua.uniformID) INNER JOIN [Band Addresses] AS a ON ua.studentID = a.StudentID
    WHERE (((ua.[Date Assigned]) Is Not Null) AND ((ua.[Date Returned]) Is Null))
    ORDER BY u.[Part Description], u.[Part Number];
    like here:

    http://msdn.microsoft.com/en-us/libr...ffice.15).aspx

    And they suggest two queries... this is new to me. How do I do two queries at the same time?

  11. #11
    craigh is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Sep 2014
    Posts
    5
    I got it!

    Code:
    SELECT *
    FROM uniform_assignments INNER JOIN [Band Addresses] ON uniform_assignments.studentID = [Band Addresses].StudentID
    WHERE (((uniform_assignments.[Date Assigned]) Is Not Null) AND ((uniform_assignments.[Date Returned]) Is Null));
    Code:
    SELECT Uniforms.[Part Description], Uniforms.size, Uniforms.[Part Number], [Band Addresses].[Last Name], [Band Addresses].[First Name]
    FROM Uniforms, uniforms_helper_all, Uniforms LEFT JOIN uniforms_helper_all ON Uniforms.uniformID = uniform_assignments.uniformID
    ORDER BY Uniforms.[Part Description], Uniforms.[Part Number], Uniforms.size;

    I didn't understand the two query thing until I figured out I actually had to make two query objects and treat the helper like a table. then it made sense.

    Access is a bit weird about FORCING the query to include all the table/query names in the second query with the JOIN statement after (with the comma). and if you save the query and re-open it they disappear causing an error. You have to retype them in again in order to make any edits.

    anyways - thanks everyone for your help!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 11
    Last Post: 05-01-2014, 11:56 AM
  2. Replies: 3
    Last Post: 01-23-2014, 07:49 AM
  3. Replies: 0
    Last Post: 07-16-2012, 05:42 AM
  4. Replies: 6
    Last Post: 05-30-2012, 12:32 PM
  5. Replies: 1
    Last Post: 05-11-2012, 10:59 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums