473,385 Members | 1,927 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.

The Sum of data, Dependant on Dates of the month

14
Working with ACCESS 2000 SQL, I’m getting very frustrated with it now so
Any ideas would be well appreciated

I want the sum of the sales of a Salesperson for a specific month i.e. the month before.

Last month:
i.e. Salesperson ££SOLD
1 £800
2 £350


and so fourth for all my sales staff.
Expand|Select|Wrap|Line Numbers
  1. SELECT DISTINCT CarSales.Sales_Staff_No, (SELECT SUM(CS.Purchased_Price) FROM CarSales AS CS WHERE CS.Sales_Staff_No = CarSales.Sales_Staff_No) AS Sum_Of_Sales, CarSales.Date_Of_Purchase
  2. FROM CarSales;

All that happens is that it does the sum off all data in the table instead of only the the data relevant 2 the Month...

How do I get the SUM 2 be dependant on the dates of a month.
I use the >=1/10/2006 AND <=31/10/2006. But that does not work, still gives the sum of all data .

Please give sum comments this is doing my head in now
Nov 29 '06 #1
3 1793
MMcCarthy
14,534 Expert Mod 8TB
Try this ...

Expand|Select|Wrap|Line Numbers
  1. SELECT Sales_Staff_No, SUM(Purchased_Price) 
  2. FROM CarSales 
  3. WHERE Month(Date_Of_Purchase) = IIf(Month(Now()) = 1, 12, Month(Now()) - 1)
  4. GROUP BY Sales_Staff_No;
  5.  
The Month function will get the month number from any date. The IIf statement will return 12 for December if the month is January otherwise it will return the current month number -1.

This kind of function is known as an aggregate function. i.e. where sum or count type functions are used. You have to group by any fields not aggregated.

Any questions, please let me know.

Mary
Nov 30 '06 #2
owz
14
Thanx work perfect.
u where a great help.
Nov 30 '06 #3
MMcCarthy
14,534 Expert Mod 8TB
Thanx work perfect.
u where a great help.
You're welcome.

Mary
Nov 30 '06 #4

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

Similar topics

4
by: Richard Hollenbeck | last post by:
I'm trying to write some code that will convert any of the most popular standard date formats twice in to something like "dd Mmm yyyy" (i.e. 08 Jan 1908) and compare the first with the second and...
3
by: Matt | last post by:
Hello, I have a query that I would like to schedule in DTS. The criteria of this query checks for records in the table that are within the current quarter. Here is what I have. WHERE...
13
by: SimonC | last post by:
I would like to return data from the last 2 weeks of each given month in Javascript, but in 2 formats. So, the penultimate week (Monday to Sunday) and the last week (Monday to ??) I'm not...
3
by: David | last post by:
I'm new to DB2 and I need to write a query that will allow me to find specific dates instead of me having a date range asked for, I want it to be calculated. I've done this in Access by coding...
2
by: Douglas | last post by:
I have a Vehicle MOT field in my table which i have as a Date field I dont really want to hold the year, just 'dd mmm' as MOTs are the same date every year. I have the field on my form as a...
18
by: PC Datasheet | last post by:
An Access user saw my name in a newsgroup and sent me a request for help on a project. As part of the project, a list of the dates in a month was needed. For anyone needing a list of dates in a...
23
by: thebjorn | last post by:
For the purpose of finding someone's age I was looking for a way to find how the difference in years between two dates, so I could do something like: age = (date.today() - born).year but that...
5
by: veaux | last post by:
I'm thinking this is easy but can't get it. I have a table with following: Table1 Date 1/1/2007 Table2 Type 0107 (This is MMYY of above) So I'm having trouble using a query to turn the...
12
by: petter | last post by:
Hi! I have two questions: one question that regards the COUNT-function, and one about how to display a month even if I don’t have any data for that month. I have an Access database where I want...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.