473,811 Members | 2,843 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help with Cross tab query

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

TRANSFORM Sum(Expenses.Ex pense) AS SumOfExpense
SELECT Expenses.Debtor s, Expenses.Cash, Sum(Expenses.Ex pense) AS [Total
Of expense]
FROM Expenses
GROUP BY Expenses.Debtor s, Expenses.Cash
PIVOT Format([date],"mmm") In
("Jan","Feb","M ar","Apr","May" ,"Jun","Jul","A ug","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 1372
Don Sealer wrote:
How would I make this query sum the fields "expense"+"cash "

TRANSFORM Sum(Expenses.Ex pense) AS SumOfExpense
SELECT Expenses.Debtor s, Expenses.Cash, Sum(Expenses.Ex pense) AS [Total
Of expense]
FROM Expenses
GROUP BY Expenses.Debtor s, Expenses.Cash
PIVOT Format([date],"mmm") In
("Jan","Feb","M ar","Apr","May" ,"Jun","Jul","A ug","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_Crosst ab:
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","M ar","Apr","May" ,"Jun","Jul","A ug","Sep","Oct" ,"Nov","Dec" );

!Expenses_Cross tab:

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.Ex pense) AS SumOfExpense
SELECT Expenses.Debtor s, Sum(Expenses.Ca sh) AS TotalCash,
Sum(Expenses.Ex pense) AS TotalExpense, Sum([Expense])+Sum([Cash]) AS
ExpensePlusCash
FROM Expenses
WHERE (((Expenses.Deb tors) Is Not Null))
GROUP BY Expenses.Debtor s
PIVOT Format([ExpenseDate],"mmm") In
("Jan","Feb","M ar","Apr","May" ,"Jun","Jul","A ug","Sep","Oct" ,"Nov","Dec" );


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

TRANSFORM Sum(Expenses.Ex pense) AS SumOfExpense
SELECT Expenses.Debtor s, Expenses.Cash, Sum(Expenses.Ex pense) AS [Total
Of expense]
FROM Expenses
GROUP BY Expenses.Debtor s, Expenses.Cash
PIVOT Format([date],"mmm") In
("Jan","Feb", "Mar","Apr","Ma y","Jun","Jul", "Aug","Sep","Oc t","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_Crosst ab:
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","M ar","Apr","May" ,"Jun","Jul","A ug","Sep","Oct" ,"Nov","Dec" );

!Expenses_Cross tab:

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
2988
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 5/5/03 6:03 5/5/03 6:05 M1 U3 5/5/03 6:03 5/5/03 6:04 M2 : etc. There are about 40K units and 30 serving machines. The data is in
3
6421
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, Employees.LastName, TerritoryID, Employees.EmployeeID, RegionID, ProductID from Employees
9
3409
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 a triangle. Like this member A -> B->C A give his appartment to B. B gives his appartment to C and finally C gives his appartment to A Soo my query looks for matching parameters like rooms, location, size
28
3310
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 make-believe challenge in order to avoid confusing the issue further. Suppose I was hosting a dinner and I wanted to invite exactly 12 guests from my neighborhood. I'm really picky about that... I have 12 chairs besides my own, and I want them all...
4
2868
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 that links to a transaction items table that links to the products table: (User Table) UserID Other user data
9
4362
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 predecessor, I hasten to add) so that each day it creates a copy of the record for each company, changes the date to today's date, and prompts the user for any changes of ratings on that day. The resulting data table grows by approx 600 records per...
3
2812
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 sale made by one of 90 salespeople (2 years of data), and the date the sale was made. I need a report that shows a list of the salespeople down the left hand side and then for each month the total number of sales and the total value of sales. I...
3
5687
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 begin And I will have to maintain the form. I worry mostly about the caption of the cross query. How can I change the caption of a cross query without use a form. Thank you all
6
1357
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 -- -------------- -------------- --------- 1 ABC quality 8 2 ABC relevance 7
2
3755
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 cross reference table to my CATALOG Table based on key words.
0
9727
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
10398
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
10133
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9204
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6889
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5554
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5692
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4339
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
2
3865
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.