Results 1 to 13 of 13
  1. #1
    johnmerlino is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Oct 2010
    Posts
    97

    Missing a parenthesis somewhere in query

    Hey all,

    I have this query:

    Code:
    SELECT left(
          [aname],
       IIF((instr([aname], " ") = 0 AND ((instr([aname], ",") = 0,
          [aname],
          IIF(instr([aname], ",") = 0,
            InStr(1,[aname]," ")-1,
            InStr(1,[aname],",")-1
            )
          )
       )
        &  ","  &
        right(
           [aname],
       IIF((instr([aname], " " = 0 AND ((instr([aname], ",") = 0,
           "",
            IIF(instr([aname], ",") = 0,
              Len(aname)-InStr(1,[aname]," "),
              Len(aname)-InStr(1,[aname],",")
             )
            )
        )
         &  " " &
        defense_final.middle_initial AS fullname INTO FinalForgottenWithMiddle
    FROM FinalForgotten INNER JOIN defense_final ON (left(FinalForgotten.aname,
       IIF((instr([aname], " ") = 0 AND ((instr([aname], ",") = 0,
          [aname],
          IIF(instr([aname], ",") = 0,
            InStr(1,FinalForgotten.[aname]," ")-1,
            InStr(1,FinalForgotten.[aname],",")-1
            )
         )
        )=defense_final.last_name) AND (right(FinalForgotten.aname,
          IIF((instr([aname], " ") = 0 AND ((instr([aname], ",") = 0,
          [aname],
           IIF(instr([aname], ",") = 0,
            Len(FinalForgotten.aname)-InStr(1,FinalForgotten.[aname]," "),
            Len(FinalForgotten.aname)-InStr(1,FinalForgotten.[aname],",")
          )
        )
       )=defense_final.first_name);
    I am missing a paranethesis somewhere and I get error Syntax Error(missing operator) in Query Expression and it highlights the word AS in AS fullname. I don't want to do significant change to this query like adding functions. I just want to figure out where the missing parenthesis is.



    Thanks for response.

  2. #2
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    TRY THIS:
    Code:
    SELECT left(
          [aname],
       IIF(instr([aname], " ") = 0 AND instr([aname], ",") = 0,
          [aname],
          IIF(instr([aname], ",") = 0,
            InStr(1,[aname]," ")-1,
            InStr(1,[aname],",")-1)))
        &  ","  &
    
        right(
           [aname],
       IIF(instr([aname], " " = 0 AND instr([aname], ",") = 0,
           "",
            IIF(instr([aname], ",") = 0,
              Len(aname)-InStr(1,[aname]," "),
              Len(aname)-InStr(1,[aname],","))))
         &  " " &
    
        defense_final.middle_initial AS fullname INTO 
    
    FinalForgottenWithMiddle
    FROM FinalForgotten INNER JOIN defense_final ON 
    
    left(FinalForgotten.aname,
       IIF(instr([aname], " ") = 0 AND instr([aname], ",") = 0,
          [aname],
          IIF(instr([aname], ",") = 0,
            InStr(1,FinalForgotten.[aname]," ")-1,
            InStr(1,FinalForgotten.[aname],",")-1)))
    
    =defense_final.last_name AND 
    
    right(FinalForgotten.aname,
          IIF(instr([aname], " ") = 0 AND instr([aname], ",") = 0,
          [aname],
           IIF(instr([aname], ",") = 0,
            Len(FinalForgotten.aname)-InStr(1,FinalForgotten.[aname]," "),
            Len(FinalForgotten.aname)-InStr(1,FinalForgotten.[aname],","))))
    
    =defense_final.first_name;
    are you sure the error is talking about a syntax error tho?

  3. #3
    johnmerlino is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Oct 2010
    Posts
    97
    That doesn't seem to work either. I assumed it was a parenthesis error. Because I had this before and it worked:

    Code:
    SELECT left(
          [aname], 
          IIF(instr([aname], ",") = 0,
            InStr(1,[aname]," ")-1,
            InStr(1,[aname],",")-1
            ) 
          )
        &  ","  & 
        right(
           [aname], 
           IIF(instr([aname], ",") = 0,
             Len(aname)-InStr(1,[aname]," "),
             Len(aname)-InStr(1,[aname],",") 
             )
            )
         &  " " & 
        defense_final.middle_initial AS fullname INTO FinalForgottenWithMiddle
    FROM FinalForgotten INNER JOIN defense_final ON (left(FinalForgotten.aname,
        IIF(instr([aname], ",") = 0,
          InStr(1,FinalForgotten.[aname]," ")-1,
          InStr(1,FinalForgotten.[aname],",")-1
            )
        )=defense_final.last_name) AND (right(FinalForgotten.aname,
         IIF(instr([aname], ",") = 0,
         Len(FinalForgotten.aname)-InStr(1,FinalForgotten.[aname]," "),
         Len(FinalForgotten.aname)-InStr(1,FinalForgotten.[aname],",")
          )
         )=defense_final.first_name);
    So all I am doing now is adding layer:

    Code:
    IIF((instr([aname], " ") = 0 AND ((instr([aname], ",") = 0,
    Because some of the names will not have a space or comma, so I need to account for that with this extra layer.

    Thanks for response.

  4. #4
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    well John, this doesn't make sense:
    Code:
    IIF((instr([aname], " ") = 0 AND ((instr([aname], ",") = 0,
    because there are extra and unnecessary parenthesis (3 of them) in:
    Code:
    IIF((instr([aname], " ") = 0 AND ((instr([aname], ",") = 0,
    that don't have a closing ones in the right place.

  5. #5
    johnmerlino is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Oct 2010
    Posts
    97
    Yeah but even when removing the extra paranthesis there, it still gives me same error.

  6. #6
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    Quote Originally Posted by johnmerlino View Post
    Yeah but even when removing the extra paranthesis there, it still gives me same error.
    is it too complex I wonder?

    and even if you remove just those John, the closers that you originally had in it somewhere else in the statement would still error.

    But that's irrelevant, I already gave you a correct syntax version of your statement.

    I also wonder if the relative references you have aren't causing problems. e.g. - change:
    Code:
    [aname]
    to the full:
    Code:
    TABLE.aname
    would that be an issue?

    also, can you use 'AND' in a join statement? I took my VBA database and joined 3 tables and tried the same and I got:
    Code:
    SELECT left(library.lfile, 5) & "-" & coclass.ctype & "-" & 
    
    right(method.mname, 3) INTO Table1
    
    FROM (coclass INNER JOIN library ON coclass.lid = library.lid) INNER JOIN method 
    
    ON coclass.cid = method.cid;
    why not try using the builder the fields as they are, let it auto join for you, then add your LEFT and RIGHT functions back in?

    mine above nested the joins twice. would that matter I wonder?

  7. #7
    johnmerlino is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Oct 2010
    Posts
    97
    Thanks for reply. I think the RIGHT was missing a right parenthesis but now that I add that parenthesis:

    Code:
    SELECT left(
      [aname],
     IIF(instr([aname], " ") = 0 AND instr([aname], ",") = 0,
       FinalForgotten.aname,
      IIF(instr([aname], ",") = 0,
        InStr(1,[aname]," ")-1,
        InStr(1,[aname],",")-1)))
    &  ","  &
    
    right(
       [aname],
     IIF(instr([aname], " " = 0 AND instr([aname], ",") = 0,
       "",
        IIF(instr([aname], ",") = 0,
          Len(aname)-InStr(1,[aname]," "),
          Len(aname)-InStr(1,[aname],",")))))
     &  " " &
    
    defense_final.middle_initial AS fullname INTO 
    
    FinalForgottenWithMiddle
    FROM FinalForgotten INNER JOIN defense_final ON 
    
    left(FinalForgotten.aname,
     IIF(instr([aname], " ") = 0 AND instr([aname], ",") = 0,
      FinalForgotten.aname,
      IIF(instr([aname], ",") = 0,
        InStr(1,FinalForgotten.[aname]," ")-1,
        InStr(1,FinalForgotten.[aname],",")-1)))=defense_final.last_name AND 
    
    right(FinalForgotten.aname,
      IIF(instr([aname], " ") = 0 AND instr([aname], ",") = 0,
      [aname],
       IIF(instr([aname], ",") = 0,
        Len(FinalForgotten.aname)-InStr(1,FinalForgotten.[aname]," "),
        Len(FinalForgotten.aname)-InStr(1,FinalForgotten.[aname],","))))=defense_final.first_name;
    I get an error:
    "Missing ), ], or Item in query expression" and it places the cursor on the first AND.

    Thanks for response.

  8. #8
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    John, if I understand correctly, you are selecting "firstname,lastname middle" from the matching list.

    I think there could be some easier way to achieve this.

    Code:
    SELECT replace(aname," ", ",") &  " " & defense_final.middle_initial AS fullname INTO FinalForgottenWithMiddle
    FROM FinalForgotten INNER JOIN defense_final ON 
    left(aname, len(first_name))=first_name and 
    left(aname,len(first_name)+1)<(first_name & ".") AND 
    right(aname,len(last_name)=last_name and 
    right(aname,len(last_name)+1)<(last_name & ".")
    some conditions must apply to run this query successfully.
    ================================================== ======
    In you query, you miss len() around aname:

    Code:
    SELECT left(
      [aname],
     IIF(instr([aname], " ") = 0 AND instr([aname], ",") = 0,
       FinalForgotten.aname,
      IIF(instr([aname], ",") = 0,
        InStr(1,[aname]," ")-1,
        InStr(1,[aname],",")-1)))
    &  ","  &
    
    right(
       [aname],
     IIF(instr([aname], " " = 0 AND instr([aname], ",") = 0,
       "",
        IIF(instr([aname], ",") = 0,
          Len(aname)-InStr(1,[aname]," "),
          Len(aname)-InStr(1,[aname],",")))))
     &  " " &
    
    defense_final.middle_initial AS fullname INTO 
    
    FinalForgottenWithMiddle
    FROM FinalForgotten INNER JOIN defense_final ON 
    
    left(FinalForgotten.aname,
     IIF(instr([aname], " ") = 0 AND instr([aname], ",") = 0,
      FinalForgotten.aname,    should be len(aname],
      IIF(instr([aname], ",") = 0,
        InStr(1,FinalForgotten.[aname]," ")-1,
        InStr(1,FinalForgotten.[aname],",")-1)))=defense_final.last_name AND 
    
    right(FinalForgotten.aname,
      IIF(instr([aname], " ") = 0 AND instr([aname], ",") = 0,
      [aname],  should be len(aname)
       IIF(instr([aname], ",") = 0,
        Len(FinalForgotten.aname)-InStr(1,FinalForgotten.[aname]," "),
        Len(FinalForgotten.aname)-InStr(1,FinalForgotten.[aname],","))))=defense_final.first_name;

  9. #9
    johnmerlino is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Oct 2010
    Posts
    97
    Thanks for response but still get an error "Missing ), ], or Item in query expression":
    Code:
    SELECT left(
      [aname],
     IIF(instr([aname], " ") = 0 AND instr([aname], ",") = 0,
       Len(FinalForgotten.aname),
      IIF(instr([aname], ",") = 0,
        InStr(1,[aname]," ")-1,
        InStr(1,[aname],",")-1)))
    &  ","  &
    
    right(
       [aname],
     IIF(instr([aname], " ") = 0 AND instr([aname], ",") = 0,
       "",
        IIF(instr([aname], ",") = 0,
          Len(aname)-InStr(1,[aname]," "),
          Len(aname)-InStr(1,[aname],","))))
     &  " " &
    
    defense_final.middle_initial AS fullname INTO FinalForgottenWithMiddle
    FROM FinalForgotten INNER JOIN defense_final ON 
    
    left(FinalForgotten.aname,
       IIF(instr([aname], " ") = 0 AND instr([aname], ",") = 0,
          Len(FinalForgotten.aname),
          IIF(instr([aname], ",") = 0,
            InStr(1,FinalForgotten.[aname]," ")-1,
            InStr(1,FinalForgotten.[aname],",")-1)))
    
     =defense_final.last_name AND 
    
     right(FinalForgotten.aname,
          IIF(instr([aname], " ") = 0 AND instr([aname], ",") = 0,
         Len(FinalForgotten.aname),
           IIF(instr([aname], ",") = 0,
            Len(FinalForgotten.aname)-InStr(1,FinalForgotten.[aname]," "),
            Len(FinalForgotten.aname)-InStr(1,FinalForgotten.[aname],","))))
    
    =defense_final.first_name;
    Also, while your other query looks nicer, you specify a first_name field that doesn't exist. So how can I compare a first_name field if aname contains both first and last? That's why I had to break it up in above query.

  10. #10
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    Also, while your other query looks nicer, you specify a first_name field that doesn't exist. So how can I compare a first_name field if aname contains both first and last? That's why I had to break it up in above query.
    Last_name is from table defense_final.

    I should exchange the places of last_name and first_name.

  11. #11
    johnmerlino is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Oct 2010
    Posts
    97
    Thanks for responses. Once again, it was ultimately missing paranethesis that caused the compiler to throw exception. I think it's time to learn so VBA though. Wish it was more like PHP and JavaScript though, at least with function declarations and variable assignment.

  12. #12
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    SELECT left(
    [aname],
    IIF(instr([aname], " ") = 0 AND instr([aname], ",") = 0,
    Len(FinalForgotten.aname),
    IIF(instr([aname], ",") = 0,
    InStr(1,[aname]," ")-1,
    InStr(1,[aname],",")-1)))
    & "," &

    right(
    [aname],
    IIF(instr([aname], " ") = 0 AND instr([aname], ",") = 0,
    "", should be 0 or len("")
    IIF(instr([aname], ",") = 0,
    Len(aname)-InStr(1,[aname]," "),
    Len(aname)-InStr(1,[aname],","))))
    & " " &

    defense_final.middle_initial AS fullname INTO FinalForgottenWithMiddle
    FROM FinalForgotten INNER JOIN defense_final ON

  13. #13
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    I tested this query and it worked:
    SELECT replace(aname," ", ",") & " " & middle_initial AS fullname
    FROM FinalForgotten as a INNER JOIN defense_final as b ON
    left(a.aname, len(b.first_name))=b.first_name and
    left(a.aname,len(b.first_name)+1)<(b.first_name & ".") AND
    right(a.aname,len(b.last_name))=b.last_name and
    right(a.aname,len(b.last_name)+1)<(b.last_name & ".")

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

Similar Threads

  1. ok what am i missing here ?
    By baseborn in forum Forms
    Replies: 6
    Last Post: 12-21-2010, 01:46 PM
  2. Missing file
    By faceofevil in forum Access
    Replies: 2
    Last Post: 11-01-2010, 10:55 PM
  3. How to find missing date query
    By twhite in forum Queries
    Replies: 8
    Last Post: 09-02-2010, 02:42 PM
  4. Missing Counts that = 0 in query results
    By dandhjohn in forum Queries
    Replies: 1
    Last Post: 01-29-2010, 11:28 AM
  5. Replies: 1
    Last Post: 10-07-2009, 07:36 AM

Tags for this Thread

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