Results 1 to 7 of 7
  1. #1
    Russellh is offline Advanced Beginner
    Windows 8 Access 2010 32bit
    Join Date
    Apr 2014
    Posts
    68

    Create a column based on a query


    I have 2 tables that I cannot link.
    I need to take the server order # (153001 example) and convert it to 050000000000153001 which I can do.
    Then I can use that number to pull the note that I need from the other table that I cannot link.

    Query 1 I am pulling Service Order info from SOTABLE
    in Query 1 I need to add a field that will show the 2nd note from NotesDetail table.
    The fields for the NotesDetail table are NoteKey, Date, NoteItem.
    In order to get the note I am after I would have to query the NotesDetail table for the following:
    NoteKey = 050000000000153001
    NoteItem = 000102

    What is the syntax for creating a field in query 1 that will show that information?

    Note: [query notesdetail where notekey="050000000000153001" and noteitem="000102"]

    If it can't be done in a way that I can enter into a blank field (from design view) as I started in the previous line, how would I do it?

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Why don't you join the tables in query? You can use the field constructed with the conversion expression as one side of the JOIN clause.

    Then apply appropriate filter criteria.
    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.

  3. #3
    Russellh is offline Advanced Beginner
    Windows 8 Access 2010 32bit
    Join Date
    Apr 2014
    Posts
    68
    I am not allowed to modify any of the tables. So I can't add the new field to it. I'm only able to create querries on the tables. I can create my own tables but then the copy wouldn't update itself live.

  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
    52,929
    I am not suggesting you modify tables.

    I am suggesting joining tables in query. One side of the join will be calculated field and the other side will be natural field. Something like:

    SELECT table1.*, table2.* FROM table1 INNER JOIN table1 ON "050000000000" & table1.fieldname AS SONUM = table2.ServiceNumber;

    Won't be able to see that join in query designer view. Build it in SQL view.

    Alternative is to create a query object with the calculated field, no joins.

    Then use that query object in another query to join with table.
    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
    Russellh is offline Advanced Beginner
    Windows 8 Access 2010 32bit
    Join Date
    Apr 2014
    Posts
    68
    Hey June,
    I am too much of a novice to follow you I think. Here is a screenshot of what I am trying to do.Click image for larger version. 

Name:	ACCESSJPEG1.png 
Views:	6 
Size:	125.6 KB 
ID:	18470

    The last column on the right at the bottom recreates the CANOTEKEY field in the unlinked table.
    I need to create another field that shows the CATEXT field with conditions.
    The conditions are 1) CANOTEKEY has to be the same for both
    2) CANOTEITEM has to equal 000102

    If that explains it any better. I tried playing with joins. Since I am creating the CANOTEKEY field in table1 by adding text strings together I cannot find a way to use that to create a join to the canotekey in the unjoined table. For every canotekey there are several lines of notes. Each line is noted by 000101 (first line) and 000102 (2nd line) and so on. Basically I need the 2nd line. In other words in the unjoined table there are several records for the same canotekey and so I need the catext field where canotekey = canotekey (from my created field) and canoteitem = 000102.

    I'm sure I am probably over complicating this but I can't seem to make it work.

  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
    52,929
    Queries can be used like tables in queries.

    Using my second suggestion, remove the unlinked table from that query and save the query.

    Now build another query that joins the first query to the 'unlinked' table.

    NOTE: the & is preferred concatenation operator.
    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
    Russellh is offline Advanced Beginner
    Windows 8 Access 2010 32bit
    Join Date
    Apr 2014
    Posts
    68
    Super thanks. Worked like a charm! I just needed read what you were telling me in a way I could grasp.
    MANY THANKS again!!

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

Similar Threads

  1. Replies: 4
    Last Post: 04-22-2014, 08:23 AM
  2. Query to Set Value Based off another Column
    By breakingme10 in forum Queries
    Replies: 2
    Last Post: 03-31-2014, 03:13 PM
  3. Replies: 5
    Last Post: 05-01-2013, 11:39 AM
  4. create comma delimited string from column in query
    By younggunnaz69 in forum Queries
    Replies: 2
    Last Post: 04-30-2011, 04:26 PM
  5. Replies: 1
    Last Post: 04-15-2010, 02:07 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