Results 1 to 6 of 6
  1. #1
    securitywyrm is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2013
    Posts
    97

    How to merge multiple querities into sub-queries on a single query?

    Thank you everyone for your help with this project. I think I'm at the point where I can ask the right question.



    I have a series of queries used for a fiscal dashboard. The main data source is a list of fund control points (FCP), and then I have a separate queries to show budget, spent, obligated, planned, etc. What I'd like to do is take each of these queries and turn them into an expression in a larger query. So for example...

    Code:
    SELECT TFiscalData.FCP, Sum(TFiscalData.Cost) AS DashBudgetTotal
    FROM TFiscalData
    WHERE (((TFiscalData.TransactionPrimary)="BUDGET"))
    GROUP BY TFiscalData.FCP;
    and
    Code:
    SELECT TFiscalData.FCP, Sum(TFiscalData.Cost) AS DashObligatedTotal
    FROM TFiscalData
    WHERE (((TFiscalData.TransactionPrimary)="Expense"))
    GROUP BY TFiscalData.FCP, TFiscalData.PoStatus
    HAVING (((TFiscalData.PoStatus)="Obligated"));
    Would each be a subquery in a larger query. This would make it exponentially easier to change it later for say, changing what fiscal year it's looking at. Unfortunately I only understand the most basic of expressions, like "DashBudgetTotal: Sum(Cost)", what do I need to do to turn all that SQL into an expression?

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Why is the Obligated summation grouped by PoStatus and Budget is not?
    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
    securitywyrm is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2013
    Posts
    97
    Quote Originally Posted by June7 View Post
    Why is the Obligated summation grouped by PoStatus and Budget is not?
    Budget entries don't have a PO status. I'll also have some other strange ones, like cost transfers where the primary field is "Cost transfer" but the secondary will either be "Received" or "Disbursed" and thus the display field will be one minus the other.

    If it helps to put this in context, this is federal government accounting.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    I don't think your vision of a single big query that is a 'merge' of multiple queries with varying grouping is realistic.

    The two queries don't have the same grouping so they can't be related. If they both grouped on only FCP, then they could be either joined to each other (if one of them has all possible FCP values) or both joined to a table of unique FCP values.
    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
    securitywyrm is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2013
    Posts
    97
    Quote Originally Posted by June7 View Post
    I don't think your vision of a single big query that is a 'merge' of multiple queries with varying grouping is realistic.

    The two queries don't have the same grouping so they can't be related. If they both grouped on only FCP, then they could be either joined to each other (if one of them has all possible FCP values) or both joined to a table of unique FCP values.
    They're all going to be grouped by FCP. My question is, what's the process to turn a query into a subquery?

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    They may all include FCP as one group parameter but you already show one query that has an additional group parameter that is not shared by the other query you show.

    Usually I would first build the inner query and save it. Then I build another query that references the first query to get the proper syntax. Then I copy/paste the SQL statement from the first query into the appropriate location of the second query. Delete the first query object. However, there are some nested queries where the inner statement cannot be a standalone query. In which case I simply follow an example and type the full structure into SQL View.

    Here is an article with several examples of nested queries http://allenbrowne.com/subquery-01.html
    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. Merge Multiple Rows To Single Row
    By Juan4412 in forum Programming
    Replies: 12
    Last Post: 05-23-2017, 09:43 AM
  2. Replies: 17
    Last Post: 08-09-2015, 09:45 AM
  3. Exporting Multiple Queries to a single Text File
    By sam.eade in forum Import/Export Data
    Replies: 6
    Last Post: 05-13-2014, 09:24 AM
  4. Replies: 5
    Last Post: 08-29-2011, 09:37 AM
  5. Replies: 7
    Last Post: 08-05-2011, 10:59 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