473,385 Members | 1,409 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Help with Cross tab query

How would I make this query sum the fields "expense"+"cash"

TRANSFORM Sum(Expenses.Expense) AS SumOfExpense
SELECT Expenses.Debtors, Expenses.Cash, Sum(Expenses.Expense) AS [Total
Of expense]
FROM Expenses
GROUP BY Expenses.Debtors, Expenses.Cash
PIVOT Format([date],"mmm") In
("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug"," Sep","Oct","Nov","Dec");

I can't figure this out and I feel pretty dumb about it.
Thanks again,
Don..............
Nov 13 '05 #1
2 1357
Don Sealer wrote:
How would I make this query sum the fields "expense"+"cash"

TRANSFORM Sum(Expenses.Expense) AS SumOfExpense
SELECT Expenses.Debtors, Expenses.Cash, Sum(Expenses.Expense) AS [Total
Of expense]
FROM Expenses
GROUP BY Expenses.Debtors, Expenses.Cash
PIVOT Format([date],"mmm") In
("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug"," Sep","Oct","Nov","Dec");

I can't figure this out and I feel pretty dumb about it.
Thanks again,
Don..............


After changing [Date] to [ExpenseDate],

Expenses:

ExpenseID Expense Cash Debtors ExpenseDate
1 $100 $20 Debtors1 1/1/05
2 $200 $40 Debtors2 1/2/05
3 $300 $60 Debtors3 2/2/05
4 $400 $80 Debtors4 2/5/05
5 $500 $100 Debtors5 3/1/05

Expenses_Crosstab:
TRANSFORM Sum(Expense) + Sum(Cash) AS TheValue SELECT Debtors,
Sum(Cash) AS [TotalCash], Sum(Expense) As [TotalExpense], Sum(Expense)
+ Sum(Cash) AS ExpensePlusCash FROM Expenses GROUP BY Debtors, Cash,
Expense PIVOT Format([ExpenseDate],"mmm") In
("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug"," Sep","Oct","Nov","Dec");

!Expenses_Crosstab:

Debtors TotalCash TotalExpense ExpensePlusCash Jan Feb ...
Debtors1 $20 $120 $120 $120
Debtors2 $40 $200 $240 $240
Debtors3 $60 $300 $360 $360
Debtors4 $80 $400 $80 $480
Debtors5 $100 $500 $600 $600

I'm not sure that's what you're looking for. I liked the way the "In"
part handled Null dates and ensured that all months show up. I'm
learning from you. Thanks.

James A. Fortune

Nov 13 '05 #2
Thanks for your reply. I'd like to take credit for the "in" but it was
given to me by someone.
As for the suggestion and SQL you gave me. I put the SQL into my query
but it doesn't give the results I was looking for. I worked with what
you gave me and came up with this. As far as I can tell it gives me the
exact results I was looking for. Only took minor alterations to what
you suggested (just took me awhile to figure it out). You put me on the
right track, thanks very much.
Don..........

TRANSFORM Sum(Expenses.Expense) AS SumOfExpense
SELECT Expenses.Debtors, Sum(Expenses.Cash) AS TotalCash,
Sum(Expenses.Expense) AS TotalExpense, Sum([Expense])+Sum([Cash]) AS
ExpensePlusCash
FROM Expenses
WHERE (((Expenses.Debtors) Is Not Null))
GROUP BY Expenses.Debtors
PIVOT Format([ExpenseDate],"mmm") In
("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug"," Sep","Oct","Nov","Dec");


ji********@compumarc.com wrote:
Don Sealer wrote:
How would I make this query sum the fields "expense"+"cash"

TRANSFORM Sum(Expenses.Expense) AS SumOfExpense
SELECT Expenses.Debtors, Expenses.Cash, Sum(Expenses.Expense) AS [Total
Of expense]
FROM Expenses
GROUP BY Expenses.Debtors, Expenses.Cash
PIVOT Format([date],"mmm") In
("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug" ,"Sep","Oct","Nov","Dec");

I can't figure this out and I feel pretty dumb about it.
Thanks again,
Don..............

After changing [Date] to [ExpenseDate],

Expenses:

ExpenseID Expense Cash Debtors ExpenseDate
1 $100 $20 Debtors1 1/1/05
2 $200 $40 Debtors2 1/2/05
3 $300 $60 Debtors3 2/2/05
4 $400 $80 Debtors4 2/5/05
5 $500 $100 Debtors5 3/1/05

Expenses_Crosstab:
TRANSFORM Sum(Expense) + Sum(Cash) AS TheValue SELECT Debtors,
Sum(Cash) AS [TotalCash], Sum(Expense) As [TotalExpense], Sum(Expense)
+ Sum(Cash) AS ExpensePlusCash FROM Expenses GROUP BY Debtors, Cash,
Expense PIVOT Format([ExpenseDate],"mmm") In
("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug"," Sep","Oct","Nov","Dec");

!Expenses_Crosstab:

Debtors TotalCash TotalExpense ExpensePlusCash Jan Feb ...
Debtors1 $20 $120 $120 $120
Debtors2 $40 $200 $240 $240
Debtors3 $60 $300 $360 $360
Debtors4 $80 $400 $80 $480
Debtors5 $100 $500 $600 $600

I'm not sure that's what you're looking for. I liked the way the "In"
part handled Null dates and ensured that all months show up. I'm
learning from you. Thanks.

James A. Fortune

Nov 13 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: News | last post by:
Folks, I need help with this task. I have a set of data that needs to be plotted on timeline chart. Example: Unit ProcStart ProcEnd Machine U1 5/5/03 6:01 5/5/03 6:04 M1 U2 ...
3
by: Prem | last post by:
Hi, I am having many problems with inner join. my first problem is : 1) I want to know the precedance while evaluating query with multiple joins. eg. select Employees.FirstName,...
9
by: majsen | last post by:
Hi, I have problem running this query. It will time out for me... My database are small just about 200 members. I have a site for swaping appartments (rental). my query should look for match in...
28
by: stu_gots | last post by:
I have been losing sleep over this puzzle, and I'm convinced my train of thought is heading in the wrong direction. It is difficult to explain my circumstances, so I will present an identical...
4
by: jimh | last post by:
I'm not a SQL expert. I want to be able to write a stored procedure that will return 'people who bought this product also bought this...'. I have a user table that links to a transaction table...
9
by: Dom Boyce | last post by:
Hi First up, I am using MS Access 2002. I have a database which records analyst rating changes for a list of companies on a daily basis. Unfortunately, the database has been set up (by my...
3
by: amanda | last post by:
Hope someone can help me with this - I've been staring at it stupidly for hours now, convinced there must be an easy way to achieve the results I want: I have a very large table recording every...
3
by: maffonso | last post by:
Hi guys, I have built a cross reference query (columns is year). I would like to change the caption and adjust others things. The best way would be to wrap the query in a form, but soon 2007 will...
6
by: Daveo | last post by:
Hi there, I have a query (say it's called "Query1") that contains data in the following structure: id reference scoretype score -- -------------- -------------- ...
2
by: lenygold via DBMonster.com | last post by:
Hi Everebody: I have a table: CREATE TABLE CROSS_REFERENCE (ROW# INTEGER NOT NULL ,KEY_WORD CHAR(16) NOT NULL ,QUERY_DESCR VARCHAR(330) NOT NULL ,PRIMARY KEY (ROW#,KEY_WORD)); It is a...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...

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.