Solved

how do I create a query that will sum the records of the past week in ms access 2003

Posted on 2011-03-10
10
392 Views
Last Modified: 2012-05-11
how do I create a query that will sum the records of the past week in ms access 2003
0
Comment
Question by:Dov_B
10 Comments
 
LVL 119

Expert Comment

by:Rey Obrero
Comment Utility
by past week, what does it include, last week monday to Sunday?
0
 
LVL 38

Assisted Solution

by:Aaron Tomosky
Aaron Tomosky earned 100 total points
Comment Utility
Select sum(sumcolumn) from tablename
Where datecolum between('2011-03-01','2011-03-07')
group by sumcolumn
0
 

Author Comment

by:Dov_B
Comment Utility
I sum from sunday through thursday
how do I write the sql in msa access so its not hardcoded and does not need to be rewritten each week
0
 
LVL 119

Expert Comment

by:Rey Obrero
Comment Utility
for last monday and last friday dates as past week

select sum([FieldName])
from tableName
where [dateField] between Dateadd("d", - 6 - Weekday(Date, 2),date) and dateadd("d",-2-weekday(date,2),Date)
0
 
LVL 119

Expert Comment

by:Rey Obrero
Comment Utility
from sunday through thursday, use this

select sum([FieldName])
from tableName
where [dateField] between Dateadd("d", -7 - Weekday(Date, 2),date) and dateadd("d",-3-weekday(date,2),Date)
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 119

Accepted Solution

by:
Rey Obrero earned 275 total points
Comment Utility
you may need to use Date()  instead of Date

from sunday through thursday, use this

select sum([FieldName])
from tableName
where [dateField] between Dateadd("d", -7 - Weekday(Date(), 2),date()) and dateadd("d",-3-weekday(date(),2),Date())
0
 

Author Comment

by:Dov_B
Comment Utility
Thanks you have beeen a great help!
when I run the query it asks me to enter parameter value
how can I get it to run without asking me anything?
0
 

Author Comment

by:Dov_B
Comment Utility
actualy I added the brackets and it stopped asking me for a parameter but did not return any records for this week unless I changed my system date to the 15 th
0
 
LVL 49

Assisted Solution

by:Gustav Brock
Gustav Brock earned 125 total points
Comment Utility
This should do. Find first and last date of this week, subtract one week for both, and subtract further two from the last date (Saturday) to obtain Thursday:

select
  sum([FieldName])
from
  tableName
where
  [dateField] between
    DateAdd("d", 1 - WeekDay(Date(), 1) - 7, Date())
    And
    DateAdd("d", 7 - WeekDay(Date(), 1) - 7 - 2, Date());

/gustav
0
 
LVL 119

Expert Comment

by:Rey Obrero
Comment Utility
Dov_B,

upload a copy of the db
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now