473,473 Members | 1,823 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Query problem

1 New Member
I need to create a report that shows the hours a store is open.

I have a table that displays the store number, end of week date, Sunday Hours, Monday Hours, Tuesday Hours, etc. I have attached a small screenshot of the data format.

Some weeks the store hours for each day are the same. In that case, if the weeks are adjacent to each other, I would like to combine the dates into a date range. For example

Store Date Sun Mon Tues
A 11/23/08 10:00 am - 10:00 pm 8:00 am - 10:00 pm 8:00 am - 10:00 pm

A 11/30/08 10:00 am - 10:00 pm 8:00 am - 10:00 pm 8:00 am - 10:00 pm

A 12/07/08 9:00 am - 10:00 pm 8:00 am - 10:00 pm 8:00 am - 10:00 pm

A 12/14/08 10:00 am - 10:00 pm 8:00 am - 10:00 pm 8:00 am - 10:00 pm


Using the sample data above, I would like the output to be as follows.

Store Date Range Sun Mon Tues
A 11/23/08 - 11/30/08 10:00 am - 10:00 pm 8:00 am - 10:00 pm 8:00 am - 10:00 pm
A 12/07/08 9:00 am - 10:00 pm 8:00 am - 10:00 pm 8:00 am - 10:00 pm
A 12/14/08 - 11/30/08 10:00 am - 10:00 pm 8:00 am - 10:00 pm 8:00 am - 10:00 pm

Since the first two weeks have the same hours for each day, the two weeks are combined into one line with a date range.

The third week has different hours, so it is listed on a seperate line

The fourth week has the same hours as the first two weeks, but since it was seperated by week three, that had different hours, it is listed on a seperate line.

I am not sure how to accomplish this. If anyone has any way to make this happen I would greatly appreciate it.

screenshot.jpg
Dec 2 '08 #1
2 944
FishVal
2,653 Recognized Expert Specialist
Hello.

I recall something similar already discussed here.
However that is not an option for you until you normalize your database.

Regards,
Fish
Dec 2 '08 #2
ChipR
1,287 Recognized Expert Top Contributor
The only way I can see doing this is to open the recordset of the table and step through each record. Here's an outline of how it would work.
Expand|Select|Wrap|Line Numbers
  1. if records.eof then exit sub
  2. lastStore = records!store
  3. beginDate = records!date
  4. lastDate = records!date
  5. lastSun = records!Sun
  6. lastMon = records!Mon
  7. ...
  8. records.movenext
  9.  
  10. while not records.eof
  11.   if not(records!store = lastStore & records!Sun = lastSun & records!Mon = lastMon ...) then
  12.     'found the end of a date range
  13.     strDateRange = iif(lastDate = beginDate, lastDate, beginDate & " - " lastDate)
  14.     insert into NewTable values (lastStore, strDateRange, lastSun, lastMon...)
  15.     lastStore=records!Store
  16.     lastDate=records!Date
  17.     beginDate=records!Date
  18.     lastSun=records!Sun
  19.     ...
  20.   else
  21.     lastDate=records!Date
  22.   end if
  23.   records.movenext
  24. wend
So you start a date range, saving it's values. You move to the next record and compare it to the previous, and if it's different you need to insert into the table and start a new date range. If it's the same, you just move on to the next record, until you find the end of that range.
Dec 2 '08 #3

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

Similar topics

13
by: Wescotte | last post by:
Here is a small sample program I wrote in PHP (running off Apache 1.3.31 w/ PHP 5.0.1) to help illustrates problem I'm having. The data base is using DB2 V5R3M0. The client is WinXP machine using...
3
by: Brian Oster | last post by:
After applying security patch MS03-031 (Sql server ver 8.00.818) a query that used to execute in under 2 seconds, now takes over 8 Minutes to complete. Any ideas on what the heck might be going...
1
by: Jeff Blee | last post by:
I hope someone can help me get this graph outputing in proper order. After help from Tom, I got a graph to display output from the previous 12 months and include the average of that output all in...
8
by: Adam Louis | last post by:
I would like help resolving this problem. I'm a novice who's been hired to query a hospital database and extract useful information, available to me only in a dynamically generated, downloadable...
6
by: Martin Lacoste | last post by:
Ok, before I headbutt the computer... don't know why when I add criteria in a query, I get an 'invalid procedure call'. I also don't know why after searching the help in access, the various access...
4
by: Apple | last post by:
1. I want to create an autonumber, my requirement is : 2005/0001 (Year/autonumber), which year & autonumber no. both can auto run. 2. I had create a query by making relation to a table & query,...
11
by: Andy_Khosravi | last post by:
My problem: I'm having trouble with a query taking much too long to run; a query without any criteria evaluating only 650 records takes over 300 seconds to run (over the network. On local drive...
4
by: Konrad Hammerer | last post by:
Hi! I have the following problem: I have a query (a) using another query (b) to get the amount of records of this other query (b), means: select count(MNR) as Number from...
4
by: Stan | last post by:
I am using MS Office Access 2003 (11.5614). My basic question is can I run a query of a query datasheet. I want to use more that one criteria and can not get that query to work. I thought I...
2
by: existential.philosophy | last post by:
This is a new problem for me: I have some queries that open very slowly in design view. My benchmark query takes about 20 minutes to open in design view. That same query takes about 20 minutes...
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
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,...
1
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...
0
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,...
0
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...
0
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...
0
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 ...
0
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...

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.