473,586 Members | 2,639 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to combine 3 tables

418 Contributor
I have three tables, tblAP, tblPayroll and tblAllocation. Each records three separate expenses. All three are related by FK ECHOID, each has common fields such as AccountNo, FundNo, GrantNo, SubClassNo, ProjectNo and Amount

Originally I created these 3 and was able to generate combined reports using queries. But I have been unable to use these queries and tie it to create a report that will show Revenue, Expenses and balance side by side. I am running into outer join ambiguity problem which I don't know how to solve.

I was wondering if I can create a 4th table called tblGrantExpense s that will automatically combine expenses from these tables perhaps it will allow me to create a report using tblGrantBudget (for revenue) and tblGrantExpense s (for expenses).

Can someone please give me some guidence? Many thanks.
Jun 30 '09 #1
13 3242
yarbrough40
320 Contributor
do all three tables have Revenue, Expenses and balance fields in them?

any specifics on what you are trying to accomplish would really help like:
which exact field names you are needing for the report
which tables do those fields reside in (are they all of them?)

and can you describe the result your looking for a bit more? I'm not understanding the 'side by side' you mentioned
Jun 30 '09 #2
yarbrough40
320 Contributor
as long as your FK ECHOID field is present in all three tables you should be able to do as many joins as you like. Perhaps can you post an example of the working code and an example of where it began giving you trouble?
Jun 30 '09 #3
MNNovice
418 Contributor
Yarborough40:

Thanks for responding to my questions.

Sample data
tblAp
ApID - PK (auto) - 1
VendorID - Number - 1 (Pulling data from tblVendor)
InvoiceDt - Date/Time - 6/7/09
InvoiceNo - Text - 002765
AccountID - Number - 5821 (pulling data from tblAccounts)
GrantFundID - Number - 872 (pulling data from tblGrantFund)
GrantNo - Text - MN900242 (automatically gets filled in once GrantFundID is selected
SubClassID - Number - 0999 (pulling data from tblSubClass
ProjectID - Number - 63740 9 (Pulling data from tblProjects)
ApAmount - Currency - $10,000

tblPayroll
PayrollID - PK (Auto) - 1
PayrollDt - Date/Time - 4/13/09
PayrollNo - Text - 09-12
AccountID through ProjectID same as tblAP
PayAmount - Currency - 25,000


tblAllocation
AllocationID - PK (auto) - 1
AllocationDt - Date/Time
AccountID through ProjectID same as tblAP
Amount - Currency - $5,000

Now tblGrantBudget has the Revenue data. Let's assume the grant number MN900242 has $100,000. Deducting these 3 expenses, this grant will have a balance of $60,000. Finding the remaining balance on a given grant is what I am trying to calculate. As new expenses are incurred in various categories (AP, payroll or Allocation) for a grant - I need to keep somewhere the remaining balance.

I cannot add tblGrant, tblGrantFunds and tblGrantBudget in a query this is where I get the outer join ambiguity problem.

I am willing to redesign the database if needed. I just want it to come out right.

Thanks for your offer of help.

M
Jul 1 '09 #4
yarbrough40
320 Contributor
if I'm understanding everything correctly this should work. you could utilize a subquery also but first try this:


Select tblGrantBudget. Amount as Revenue,
(tblAp.ApAmount + tblPayroll. PayAmount + tblAllocation.A mount) as Expenses,
tblGrantBudget. Amount - (tblAp.ApAmount + tblPayroll.PayA mount + tblAllocation.A mount) as Balance
From tblGrantBudget LEFT JOIN tblAp on(tblGrantBudg et.GrantNo = tblAp.GrantNo)
LEFT JOIN tblPayroll on(tblPayroll. AccountID = tblAp.ProjectID ) LEFT JOIN tblAllocation on(tblAllocatio n. AccountID = tblAp.ProjectID )
Where tblGrantBudget. GrantNo = " MN900242"
Jul 1 '09 #5
MNNovice
418 Contributor
Okay I will try this. But, let me first let you know that I cannot filter a grant no (MN900242), I would like a query to display balance for all grants (I have about 50 grants). How do I change, if any, the SQL for this query?

thanks.
Jul 1 '09 #6
yarbrough40
320 Contributor
Select Sum(tblGrantBud get.Amount) as Revenue,
Sum(tblAp.ApAmo unt + tblPayroll. PayAmount + tblAllocation.A mount) as Expenses,
Sum(tblGrantBud get.Amount) - Sum(tblAp.ApAmo unt + tblPayroll.PayA mount + tblAllocation.A mount) as Balance
From tblGrantBudget LEFT JOIN tblAp on(tblGrantBudg et.GrantNo = tblAp.GrantNo)
LEFT JOIN tblPayroll on(tblPayroll. AccountID = tblAp.ProjectID ) LEFT JOIN tblAllocation on(tblAllocatio n. AccountID = tblAp.ProjectID )
Group By Revenue, Expenses, Balance


OR if this isn't what you want - type out an example of the result you are looking for please....
Jul 1 '09 #7
MNNovice
418 Contributor
Balance (Grant Number: 1) = Revenue - Sum(ApExpenses + PayrollExpense + AllocationCost)

Balance (Grant Number: 2) = Revenue - Sum(ApExpenses + PayrollExpense + AllocationCost)

Balance (Grant Number: 3) = Revenue - (ApExpenses + PayrollExpense + AllocationCost)
Jul 1 '09 #8
yarbrough40
320 Contributor
what I really need is an example snapshot of your expected results. so let me be clear, are you looking for a result like this?:

GrantNo ------------Revenue ----------Expenses ---------- balance
MN900242----------150,000 ---------- 40,000 -------------110,000
TK421005-----------500,000 ---------- 70,000 ------------ 430,000
GS909922 ----------80,000 ------------20,000 ------------- 60,000


if not show me where you're trying to get.
Jul 1 '09 #9
MNNovice
418 Contributor
Yes exactly.

I got an error message for the SQL. It reads: Syntax error (missing operator) in query expression From tblGrantBudget LEFT JOIN tblAp on(tblGrantBudg et.GrantNo = tblAp.GrantNo)
LEFT JOIN tblPayroll on(tblPayroll. AccountID = tblAp.ProjectID ) LEFT JOIN tblAllocation on(tblAllocatio n. AccountID = tblAp.ProjectID )
Thanks.
Jul 1 '09 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

1
2983
by: snOOp | last post by:
I am trying to combine the data from two similar tables into one query, but I need for all of the records from both tables to show up and I want the ones that have matching 'emplid' to be combined into one record showing both the 'empstatus' and 'strole' fields. The following query works, but does not combine the matching records: SELECT...
5
12980
by: Jamie Pittman via AccessMonster.com | last post by:
I have two tables with 5000 entries on them. One is based for regular time with several variables example (employee name, date,time in and out, code, customer, building) I have another table that works with overtime but has the same feilds within the table. I want to be able to run a report that combines the regular time and overtime for the...
1
23334
by: mojo | last post by:
We have set up an Access database with tables x,y, & z where we would like to have multiple people entering data into a table x. Each person has an identical copy of the database on their PC's. When the person is done entering the data into table x, we want them to e-mail their database to one person who will combine the data from table x...
2
4937
by: Reidar Jorgensen | last post by:
I have several Access databases, identical in structure, but different data. Is there an easy way to combine them all into one database? There are six tables, I just want the data from all databases merged into one database. Thanks in advance.
1
2661
by: Red | last post by:
So I inherited this db that has multiple 'orders' tables. Each order table is name for the year of the orders... i.e. 2005 is 'Orders-2005', 2006 is "Orders-2006" So, I am not allowed to change the tables (boss likes how her stuff works.. bleh...)... but I am being asked to created a way to show all the orders from the last 12 montsh...
1
1427
by: Roy | last post by:
No errors here, I'm just looking for ways to make my code more efficient. As the subject line suggests, I have a LOT of repeaters on a certain page. They are visible or hidden depending on user actions and are dispersed about the page via an "image map" style of GUI. The code behind (and associated aspx) is below, you'll note that they all...
1
3423
by: Lars E. | last post by:
Hi all. I am trying to combine data from 2 tables in one datagridview. I have tables: "Customer" and "CustomerContact". I want to display Customer information (displaying all fields in customer and some fields from customercontact) in a datagridview. I am not using sql so innerjoin is not possible.... The relation between the tables...
2
2360
by: nugz | last post by:
I want to combine 3 tables with like data then append it with a filter. Tables: NewStarts, Complaints, Memos Combine: Date, Address, Route, Pub, etc.... Then sort: previous 8 days, pub/freq for that day etc... I can already do the append filter, but I cant combine and then append. I tried a Union and did the combine.. but lack the...
1
3410
by: bluereign | last post by:
Thank you for your assistance. I am a novice looking to JOIN and append or combine records from 2 current Tables into 2 new Tables named below. I have been able to JOIN Tables with the script below. My problem is if I don’t use the WHERE clause in my script below, the script can query up to 3 records with the same “LoanNo” due to the fact that...
3
1907
by: stateemk | last post by:
Hi, I'm probably making this much harder than it needs to be, but I just can't think of how to do this. Each year, a database is created with all employees on it. I need to pull all the employees from the last five years and delete any duplicates. Each table has the exact same fields. So basically, I'm trying to combine tables from 2005,...
0
7839
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8202
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7959
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8216
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5710
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3837
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3865
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2345
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
1180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.