Page 1 of 4 1234 LastLast
Results 1 to 15 of 49
  1. #1
    JCabral is offline Novice
    Windows 10 Office 365
    Join Date
    Jul 2023
    Posts
    24

    Query between two tables

    HI
    I needed some help to make a query, to two tables that I have in an access file, which I only use to store data.
    The query is done from Excel, but my difficulty is how to define the statement in SQL, since I'm not very knowledgeable about it either.

    So that's it, I have two tables, tblTasks and tblRoutes.

    In tblTasks I have the data referring to each Task, namely who does it (OIA), its designation (TASK DESIGNATION) and the extension of that task (INSPECTION EXTENSION).

    In the table tblRoutes I have the data for each OIA to do during the week, that is, I have for a given OIA the name of the route it has to do (ROUTE) and what tasks it has to do on Monday, Tuesday, Wednesday, Thursday and Friday.



    Important: The tables must have this format and I cannot change them.

    The query I need to do is; for a given OIA and for a given Route I need to know the inspection extension (INSPECTION EXTENSION) carried out for each day of the week.


    Thanks

    NOTE: Also in here - https://www.mrexcel.com/board/thread...ables.1242093/
    I canīt upload the file
    Attached Files Attached Files
    Last edited by JCabral; 07-28-2023 at 10:43 AM. Reason: Try to add a file

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    JCabral is offline Novice
    Windows 10 Office 365
    Join Date
    Jul 2023
    Posts
    24
    Quote Originally Posted by Welshgasman View Post
    In my post I refer to this!
    Thank you for your answer

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Quote Originally Posted by JCabral View Post
    In my post I refer to this!
    Thank you for your answer
    Not until I posted of the crosspost?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  5. #5
    orange's Avatar
    orange is offline Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    JCabral,

    I think you'll be able to post attachments once you have 3 posts (if I recall correctly).
    Until then, can you briefly describe in plain English -not database jargon- a description of the"business", especially major processes.
    Perhaps also a little about yourself re programming/design experience.
    Not trying to be nosy --just trying to get some context in hopes of getting more focused responses to your posts.

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Provide sample data. Either attach file or build tables in post with the advanced post editor. Click Go Advanced button below post edit window and use the table building toolbar. Or copy/paste Access table rows.

    Are you saving a task ID in each day field? Pull tblTasks into query 5 times and join one to each day field.
    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
    JCabral is offline Novice
    Windows 10 Office 365
    Join Date
    Jul 2023
    Posts
    24
    Quote Originally Posted by Welshgasman View Post
    Not until I posted of the crosspost?
    Sorry but itīs not true, the cross-posting link is ther from the beginning!

  8. #8
    JCabral is offline Novice
    Windows 10 Office 365
    Join Date
    Jul 2023
    Posts
    24
    Orange
    Thank you for clarifying the question of not being able to put the access file here.
    As you can see, I'm a "Novice" and as I mentioned in the post, I don't have great knowledge of Access and SQL, I normally use Access just to store data and everything else is done via Excel, so having to work with these tables felt great difficulty in making the query, for which I asked for help, and that I put here because it was one of the forums that I was advised by the level of knowledge of the participants.
    Thanks again for the clarification

  9. #9
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Why do you continue to use Excel as GUI?

    Did you see post #6?
    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.

  10. #10
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    If that has not been edited, then my apologies, I only looked at the first screen and recognised the post. However you should mention on all sites where you post. Some sites will cancel you if you do not.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  11. #11
    JCabral is offline Novice
    Windows 10 Office 365
    Join Date
    Jul 2023
    Posts
    24
    June7

    I use Excel because I have a lot of calculations to do and it's easier for me to do these calculations in Excel and also because I'm more comfortable with VBA in Excel, I've never needed to use access except to store large amounts of data.
    I hadn't uploaded the file yet because I was told that I could only upload it after three posts, but after all it's possible, the Access file with the tables is already there

    Thank you very much for your help

  12. #12
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Can join TASK DESIGNATION field to each day field. Have to first change TASK DESIGNATION to short text field.
    Code:
    SELECT tblRoutes.*,
    tblTasks.[INSPECTION EXTENSION] AS MonIE, 
    tblTasks_1.[INSPECTION EXTENSION] AS TueIE, 
    tblTasks_2.[INSPECTION EXTENSION] AS WedIE, 
    tblTasks_3.[INSPECTION EXTENSION] AS ThuIE, 
    tblTasks_4.[INSPECTION EXTENSION] AS FriIE
    FROM tblTasks AS tblTasks_4 
    RIGHT JOIN (tblTasks AS tblTasks_3 
    RIGHT JOIN (tblTasks AS tblTasks_2 
    RIGHT JOIN (tblTasks AS tblTasks_1 
    RIGHT JOIN (tblTasks RIGHT JOIN tblRoutes 
    ON tblTasks.[TASK DESIGNATION] = tblRoutes.MON) 
    ON tblTasks_1.[TASK DESIGNATION] = tblRoutes.TUE) 
    ON tblTasks_2.[TASK DESIGNATION] = tblRoutes.WED) 
    ON tblTasks_3.[TASK DESIGNATION] = tblRoutes.THU) 
    ON tblTasks_4.[TASK DESIGNATION] = tblRoutes.FRI;
    Really should be saving IDTASK as foreign key in number type day fields instead. Otherwise, TASK DESIGNATION should be defined as primary key because not using IDTASK for that purpose.

    Saving OIA data into tblRoutes is duplication.

    Advise not to use spaces in naming convention and all upper case is harder to read. Better would be camel case: TaskDesignation.

    I inherited a db that used Excel as GUI (data entry/edit and reporting). The reason for Excel was also based on "lots of calculations". After 3 months I decided to eliminate Excel and put everything in Access. Much happier dealing with only one software.

    Attaching files is not restricted by number of posts but I thought posting links was (as spam deterrent). Maybe the case in another site.
    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.

  13. #13
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,566
    Hi
    Your Data displays as follows in a Report. Is this correct ?
    Attached Thumbnails Attached Thumbnails Tasks.jpg  
    You can PM me if you need further help.
    Good Reading https://docs.microsoft.com/en-gb/off...on-description

  14. #14
    JCabral is offline Novice
    Windows 10 Office 365
    Join Date
    Jul 2023
    Posts
    24
    June7

    The field names can all be changed as well as the foreign key.
    That's not a problem.
    I haven't yet tested your query but I think it's missing a point that I refer to in the post, I need these values for a certain OIA and for a certain ROUTE, that is, my question will always be "For the OIA="afteixeira" and for ROUTE="R-VRL1" what was the extension made in MON ; TUE ; WED ; THU and FRI" ? (This is an example) and I can't understand where OIA and ROUTE fit into your query.


    Thank you very much for your answer and for the clarifications.

  15. #15
    JCabral is offline Novice
    Windows 10 Office 365
    Join Date
    Jul 2023
    Posts
    24
    mike60smart

    No, this report does not make much sense.


    I'll try to explain the problem, I have certain tasks (which are in the real case roads - TASK#0001, TASK#0002 ...) that have certain extensions (INSPECTION EXTENSION), I have a table with the list of all roads for each OIA (the person doing the inspection) and the respective length of each road. This is general data.


    Then I will tell each OIA which roads they have to inspect on each day of the week, which is what I call ROUTES(R-VRL1, R-VRL2,......) and for each OIA and for each ROUTE I have which roads it inspects for MON, TUE,.... and here I have tblRoutes


    What I need to know is, for OIA="afteixeira" and for ROUTE="R-VRL1" what was the total length traveled to MON , TUE, WED,....


    I don't know if I was able to explain right what the problem is?


    Thank you very much for your answer

Page 1 of 4 1234 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 6
    Last Post: 08-17-2021, 08:42 AM
  2. Replies: 17
    Last Post: 05-10-2020, 09:49 AM
  3. Replies: 4
    Last Post: 08-24-2016, 06:48 AM
  4. Replies: 3
    Last Post: 01-20-2014, 09:04 AM
  5. Replies: 3
    Last Post: 01-05-2012, 12:04 PM

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