Results 1 to 4 of 4
  1. #1
    wizzz_wizzz is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jan 2013
    Posts
    14

    Intermediate Query

    Hi All,



    I inherited a DB whereby an intermediate query (QueryA) was created to Select some fields and create a new column using expression - named "PN" to extract part of a field: PN: (Left([A_Table1].[Part Number],3)) & (Mid([A_Table1].[Part Number],4,5)).

    The purpose is to make use of this intermediate query (and using PN) to form another query (QueryB) with another table.

    May I know is such an intermediate query a normal practice? Are there any alternative/better ways of doing it?
    Attached Thumbnails Attached Thumbnails screenshot1.jpg   screenshot2.jpg  

  2. #2
    xps35's Avatar
    xps35 is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Jun 2022
    Location
    Schiedam, NL
    Posts
    299
    This can be in one query, but not in design view. You need to do it in SQL view.
    Code:
    SELECT A_Table1.[Part Number] FROM A_Table1 INNER JOIN B_Table2 ON Left(A_Table1.[Part Number], 8) = B_Table2.[Part Number]
    Notice there is no need for left and mid function. Only one left will do.
    Groeten,

    Peter

  3. #3
    wizzz_wizzz is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jan 2013
    Posts
    14
    Quote Originally Posted by xps35 View Post
    This can be in one query, but not in design view. You need to do it in SQL view.
    Code:
    SELECT A_Table1.[Part Number] FROM A_Table1 INNER JOIN B_Table2 ON Left(A_Table1.[Part Number], 8) = B_Table2.[Part Number]
    Notice there is no need for left and mid function. Only one left will do.
    Hi, thank you for you advice. The Left and Mid function was used because the 2 Tables to be joined are as below:Click image for larger version. 

Name:	screenshot3.jpg 
Views:	13 
Size:	26.3 KB 
ID:	50158

  4. #4
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,933
    The Left and Mid function was used because the 2 Tables to be joined are as below:
    in that case your query A does not return what you believe it returns - a simple opening of the query would have shown that

    left 3 returns '071' - fine
    mid 4,5 returns '-3106' - not what you think


    So assuming your queryA is wrong and it should be mid 5,5 you can stlll apply to xps's suggestion

    Code:
    SELECT A_Table1.[Part Number] FROM A_Table1 INNER JOIN B_Table2 
    ON Left(A_Table1.[Part Number], 3) &  Mid(A_Table1.[Part Number], 5,5)= B_Table2.[Part Number]
    or you can use a cartesian query

    Code:
    SELECT A_Table1.[Part Number] FROM A_Table1, B_Table2
    WHERE Left(A_Table1.[Part Number], 3) & Mid(A_Table1.[Part Number], 5,5)= B_Table2.[Part Number]
    To answer your question, nothing wrong with using an intermediate query, all 3 methods lose the benefit of indexing so will be slow for large volumes of data. Personally I try to avoid using them because of the lack of indexing but they are simple to apply. It all depends on the overall requirement.

    To use indexing I might create an additional indexed column in table1 and populate it with the calculated value. Or I might create an intermediate table to link the two values. Or I might just index the field in table 1 and use a query like

    Code:
    SELECT A_Table1.[Part Number] FROM A_Table1, B_Table2
    WHERE A_Table1.[Part Number] Like left(Table2.[Part Number],3) & "*" and Mid(A_Table1.[Part Number], 5,5)= mid(B_Table2.[Part Number],4)
    not using an initial * with the Like means indexing can be used so the comparison on the 5 digits is on a much smaller non indexed recordset. As above, depends on your data. Your example shows all starting with 071, if that applies to all the data then not much point in this method

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

Similar Threads

  1. An intermediate table?
    By gstudio in forum Access
    Replies: 3
    Last Post: 06-14-2016, 11:04 AM
  2. Best intermediate book?
    By warmslime in forum Access
    Replies: 2
    Last Post: 01-29-2016, 02:57 PM
  3. Replies: 3
    Last Post: 05-25-2015, 05:23 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