Results 1 to 6 of 6
  1. #1
    mbake085 is offline Novice
    Windows XP Access 2007
    Join Date
    Aug 2010
    Posts
    21

    SQL Multiple Queries

    Hi Everyone,

    I am attempting to automate our budgeting document for purchasing. Here is a summary of our purchasing process:

    The budget is allocated at the VP level. Engineers from various VP groups request money to spend, that money is approved and taken out of the budget as an estimated amount. As invoices are approved and reported, the "actual" amounts are taken out of the appropriate budget pool replacing the estimated amount.

    I have the relationships made and two queries to group and create estimated and actual totals for each budget pool, which is half the battle. My problem is the final product.



    I want each VP to pull a sheet summarizing their budget data. Which includes: all budget pools, estimated amounts deducted from appropriate pools and actual amounts deducted to replace the estimate.

    My only problem is as I take the original budget data and add one of the sum queries, only the data related to that sum query is visible. I want it to include all budgets even if no estimated or actual amounts have been deducted. Any way of doing this? I haven't worked on it much, maybe a query isn't the correct way to do this...

    Thanks,

    Matt

  2. #2
    NTC is offline VIP
    Windows Vista Access 2007
    Join Date
    Nov 2009
    Posts
    2,392
    Well its very do-able; but difficult to answer in a forum setting because the correct answer depends on how you decide to set up your data structure.

    Off the cuff it seems like classic 1:Many tables Budget:Requests Requests:Invoices

    I trust you have an Access textbook and are reading thru it. It is tough to design a database otherwise.

    Hope this helps a little.

  3. #3
    mbake085 is offline Novice
    Windows XP Access 2007
    Join Date
    Aug 2010
    Posts
    21

    Update

    Could I run an update query that sets the values using a separate query?

    Thanks,

    Matt

  4. #4
    mbake085 is offline Novice
    Windows XP Access 2007
    Join Date
    Aug 2010
    Posts
    21
    Update budget
    set
    requested_other_budget=fr_tracking.requested_other _budget, requested_labor_budget=fr.tracking_requested_labor _budget, spent_other_budget=invoices.spent_other_budget, spent_labor_budget=invoices.spent_labor_budget
    from
    (select id, -sum (other_budget) as requested_other_budget, -sum (labor_budget) as requested_labor_budget from fr_tracking group by id) as fr_tracking,
    ((select id, sum (spent_other_budget) as actual_other_spent, sum (spent_labor_budget) as actual_labor_spent from (select pr, -sum (other_budget) as spent_other_budget, -sum (labor_budget) as spent_labor_budget from invoices group by pr) as invoices inner join fr_tracking on invoices.pr = fr_tracking.pr) group by id)) as invoices
    where budget.id=fr_tracking.id and invoices.id;

  5. #5
    NTC is offline VIP
    Windows Vista Access 2007
    Join Date
    Nov 2009
    Posts
    2,392
    If I understand your post - I don't think you are on the right track. It isn't that complicated and really comes down to the table structure of the data itself.

    Your core goal stated is: "I want it to include all budgets even if no estimated or actual amounts have been deducted."

    Assuming you have a budget table; then you can show all values. If there is no join data in the request table for a specific budget item ...then simply use an outer join in the query so that all budgets display in the query results.

  6. #6
    mbake085 is offline Novice
    Windows XP Access 2007
    Join Date
    Aug 2010
    Posts
    21
    Wow, thanks. Don't have much experience with this stuff, but I was starting to think it was hopeless.

    Sincerely,

    Matt

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

Similar Threads

  1. Multiple Duplicate Queries in One?
    By NewtoIT in forum Programming
    Replies: 0
    Last Post: 03-10-2011, 04:57 PM
  2. Sums of Multiple Queries
    By flsticks in forum Queries
    Replies: 5
    Last Post: 09-16-2010, 09:32 AM
  3. Multiple database queries
    By G0zzy in forum Access
    Replies: 4
    Last Post: 08-28-2009, 12:06 PM
  4. Recordsource with Multiple queries
    By darshita in forum Programming
    Replies: 1
    Last Post: 08-10-2009, 03:17 PM
  5. Help writing multiple queries
    By wz72n01 in forum Queries
    Replies: 1
    Last Post: 05-24-2009, 12:30 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