Results 1 to 6 of 6
  1. #1
    RankSinatra is offline Novice
    Windows 10 Access 2010 32bit
    Join Date
    Feb 2018
    Posts
    14

    Generate All Relevant Records From One Table Even If 2nd Table is Blank


    I have two tables I want joined into a query for calculation purposes. If table A has revenue figures from one department, table B has revenue from another department, and I want to use a query to add these revenues to a total revenue that will be deposited to the bank, the query works.

    If, however, department B was closed that day and therefore table B has no matching record for the =TODAY() criteria, I still want the equation to return table A's revenue. The problem I am running into is that with only one record (table A or Table B), the query is blank, as if the whole park is closed. I considered using an append query to add 0 value records by default, but I am willing to bet there's an easier way that doesn't avoid the issue. I kind of figure there's some SQL coding involved, which I'm not familiar with writing directly.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Why do you have multiple tables? Why not 1 table with another field for the department ID?

    Should not join these tables to each other. Should join to a master dataset of whatever the linking value is (BudgetItem, AccountNum - whatever). And probably should do aggregate queries of each table before joining to the master.

    Or merge the two tables with a UNION query and use that as source for an aggregate query.
    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
    RankSinatra is offline Novice
    Windows 10 Access 2010 32bit
    Join Date
    Feb 2018
    Posts
    14
    I was hoping I didn't have to go into this much detail, as I don't want to confuse the situation, but here we go.
    Here's my setup, its pretty complex:
    I have 3 forms referencing several tables. One form balances registers, and any money brought back more than the starting amount is deposited depending on what department that register operates under, e.g. Games, Retail, Food&Beverage, Admissions. Those are all separate deposits. I have another table for a pull from the games drop boxes, which needs to be dropped with the Games deposit as well as the register earnings. And then there's the crane game pull form, where some crane games have their own deposits and some also add to games.

    Let's make it simple: I want to add the SUM totals of the register earnings WHERE department = "games", the SUM totals of the drop box money, and the SUM total of the cranes WHERE the deposit location is Games and not ELAUT, the crane company (this distinction is specified in field 2 in the crane pull table, field 1 being the name of the crane).

    I've got the individual sum queries, and when added together I get the right amount for the Games deposit. But if there's no record in the Cranes table or the Games table, the query returns no records at all. Ive looked up different join types and they aren't producing any different result.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Not quite sure what "dropped with the Games deposit as well as the register earnings" means. But it's not really relevant what your forms do, the question is about data relationships and I see no info that alters my advice.

    If you want to provide db for analysis, follow instructions at bottom of my post.
    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
    RankSinatra is offline Novice
    Windows 10 Access 2010 32bit
    Join Date
    Feb 2018
    Posts
    14
    I mention the forms because it is important. The database is designed so that multiple users can input multiple things, like one user is reconciling register money while another user inputs the games drop box revenue and another does crane revenue. "Dropped together" means the revenue is counted and added together into one deposit bag that gets sent off to the bank. The bank has several different accounts, one for each department. I need to add the revenue for three different areas and three different tables, in one query, and I need it to work when there is no matching record on one or more tables.

    As simple as I can put it:
    table A has Bob, Smith, Games, $500, 12/20/2018. So Bob Smith worked in games and made $500 on December 20th.
    table B has Balloon Pop, $100, 12/19/2018. So Balloon Pop made $100 in the box on December 19th. No records for the 20th. No games revenue was made off of drop boxes on the 20th. Games boxes were emptied and counted on the 19th, but that's not being pulled on the query because one criteria used is =Today().
    the query has Department WHERE "Games", $500, OperatingDate WHERE =Today() from table A and a place for the game box revenue from table B, as well as the expression TotalGames which adds the $500 and the game box revenue, the sum of which gets deposited to the bank at the end of the day.
    This query returns nothing, as no record exists in table B that satisfies the =Today() function. How do I get it to show me everything from Table A and maybe a 0 or NULL string for table B, instead of just no records because one table doesn't have a matching record?

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    If query uses INNER JOIN then related records must exist in both tables. If you use LEFT or RIGHT then all records of one table will be returned but possibly not all from other.

    You haven't provided sample data nor even the SQL statement of query.

    I already provided two 'how to' options. A third may be to not do all in queries but build report/subreport arrangement and do summary calcs there.
    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.

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

Similar Threads

  1. Generate Blank Records
    By SSgtBarry in forum Access
    Replies: 7
    Last Post: 10-22-2017, 12:18 PM
  2. Generate report with blank linked table fields
    By e-support in forum Reports
    Replies: 14
    Last Post: 01-06-2017, 04:11 PM
  3. Replies: 8
    Last Post: 03-24-2015, 12:21 PM
  4. Replies: 4
    Last Post: 10-17-2014, 01:34 PM
  5. Blank Records in Table
    By anwaar in forum Access
    Replies: 3
    Last Post: 09-02-2011, 02:18 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