473,398 Members | 2,403 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,398 software developers and data experts.

Creating monthly records from effective date records

I need help with this apparently simple problem. I have a table with
the following records:

Effective_Date Commodity Price
10/1/2005 0
5/1/2006 2750
10/1/2006 0

Now I need to generate the following monthly records using the above
table:

Date Commodity Price
1/1/2006 0
2/1/2006 0
3/1/2006 0
4/1/2006 0
5/1/2006 2750
6/1/2006 2750
7/1/2006 2750
8/1/2006 2750
9/1/2006 2750
10/1/2006 0
11/1/2006 0
12/1/2006 0

I found a way to create this data but it is highly inefficient as it
involves 3 queries (nested). Since I am dealing with a significant
number of records, any ideas on how to get this done without multiple
queries will be highly appreciated.

Thanks,
Amit

Feb 3 '06 #1
2 2298
ka********@gmail.com wrote:
I need help with this apparently simple problem. I have a table with
the following records:

Effective_Date Commodity Price
10/1/2005 0
5/1/2006 2750
10/1/2006 0

Now I need to generate the following monthly records using the above
table:

Date Commodity Price
1/1/2006 0
2/1/2006 0
3/1/2006 0
4/1/2006 0
5/1/2006 2750
6/1/2006 2750
7/1/2006 2750
8/1/2006 2750
9/1/2006 2750
10/1/2006 0
11/1/2006 0
12/1/2006 0

I found a way to create this data but it is highly inefficient as it
involves 3 queries (nested). Since I am dealing with a significant
number of records, any ideas on how to get this done without multiple
queries will be highly appreciated.

Thanks,
Amit


First try adding an auxiliary table (tblMonthsForCalculation) and
running the single query below to see if the speed problem goes away:

tblEffective
Effective_Date Date/Time Format m/d/yyyy
Commodity Price Currency

Effective_Date Commodity Price
10/1/05 $0.00
5/1/06 $2,750.00
10/1/06 $0.00

tblMonthsForCalculation
ID AutoNumber
theYear Long No Default
theMonth Long No Default

ID theYear theMonth
1 2005 10
2 2005 11
3 2005 12
4 2006 1
5 2006 2
6 2006 3
7 2006 4
8 2006 5
9 2006 6
10 2006 7
11 2006 8
12 2006 9
13 2006 10
14 2006 11
15 2006 12
16 2007 1

qryMonthlyPrice:
SELECT DateSerial(theYear,theMonth,1) AS theDate,
Last(tblEffective.[Commodity Price]) AS [Commodity Price] FROM
tblEffective, tblMonthsForCalculation WHERE
DateSerial([theYear],[theMonth],1)>=[Effective_Date] AND theYear = 2006
GROUP BY DateSerial(theYear,theMonth,1);

!qryMonthlyPrice:
theDate Commodity Price
1/1/06 $0.00
2/1/06 $0.00
3/1/06 $0.00
4/1/06 $0.00
5/1/06 $2,750.00
6/1/06 $2,750.00
7/1/06 $2,750.00
8/1/06 $2,750.00
9/1/06 $2,750.00
10/1/06 $0.00
11/1/06 $0.00
12/1/06 $0.00

The auxiliary table only needs to start at the last effective change
date prior to the year needed for the report. I couldn't tell from
your example so I am assuming that the change dates are always on the
first. Also, I did minimal testing. Note that GROUP BY seems to order
by date when a lone GROUP BY variable is a date. I don't think an
index on Effective_Date would hurt either.

James A. Fortune
CD********@FortuneJames.com

Feb 5 '06 #2
On 3 Feb 2006 15:30:44 -0800, ka********@gmail.com wrote:
I need help with this apparently simple problem. I have a table with
the following records:

Effective_Date Commodity Price
10/1/2005 0
5/1/2006 2750
10/1/2006 0

Now I need to generate the following monthly records using the above
table:

Date Commodity Price
1/1/2006 0
2/1/2006 0
3/1/2006 0
4/1/2006 0
5/1/2006 2750
6/1/2006 2750
7/1/2006 2750
8/1/2006 2750
9/1/2006 2750
10/1/2006 0
11/1/2006 0
12/1/2006 0

I found a way to create this data but it is highly inefficient as it
involves 3 queries (nested). Since I am dealing with a significant
number of records, any ideas on how to get this done without multiple
queries will be highly appreciated.

Thanks,
Amit

Instead of making the second table, you could just use something like
the following when you want to price something out.

SELECT price from table1 where priceDate < dteDate2 AND
priceDate > dteDate1
Or, use the same type of code in a loop to create the second table
using month-beginning or ending dates.

Also, in your tables Access won't like naming a column DATE, since
that is a reserved word. Much better to call it PriceDate or
something to make it clear what you mean.
Feb 6 '06 #3

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

Similar topics

10
by: Susan M. | last post by:
I'm trying to do a query that joins two tables. The trick is that I only want it to return rows based on a certain criteria. Table 1: Inventory Fields: Inventory #, Description Table 2:...
18
by: Jeremy Weiss | last post by:
I'm trying to build a database that will handle the monthly billing needs of a small company. I'm charting everything out and here's what I see: table for customers sub table to track payments...
4
by: Jeremy Weiss | last post by:
Thanks to much help from everyone in my previous thread, I've made it a pretty fair ways into my billing/invoicing db. I'm now needing a way to cycle through all the records in a table and create...
1
by: longtim | last post by:
I have been having endless difficulty creating reports/queries that set any relevent parameters from controls in forms. I am creating an application under access 2003 but will target access...
2
by: CK | last post by:
Good Morning, I have a view that contains rate information, contractIDs, and effective dates. I need to select the rate info based on contractID and date. I can provide a date and contractID, and...
1
by: azimid | last post by:
Hello everyone, I need your help with a query. Currently I display the data in a daily format. I have a form that the users submits the date range (from say 20061224 to 20070530) and the...
7
by: Lucas_london via AccessMonster.com | last post by:
Hi I have set up a database/tables in Access based on daily timeseries data. However I would like to create two additional columns in the table as a basis to pull the data on a weekly and...
1
by: shaggawoo | last post by:
Hello from Nova Scotia Canada. Hi there, Im struggling a bit here and I thought I might seek out some advice. Nice to meet you all. My situation is that im running a database that records...
2
by: livmacca | last post by:
Hi, I am trying to create a web page whereby I first read data from Oracle Database and display the records out on the data grid. The data displayed is in order of one attribute say 'A' meaning...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
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...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.