473,804 Members | 2,124 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2325
ka********@gmai l.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 (tblMonthsForCa lculation) 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

tblMonthsForCal culation
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(theY ear,theMonth,1) AS theDate,
Last(tblEffecti ve.[Commodity Price]) AS [Commodity Price] FROM
tblEffective, tblMonthsForCal culation WHERE
DateSerial([theYear],[theMonth],1)>=[Effective_Date] AND theYear = 2006
GROUP BY DateSerial(theY ear,theMonth,1) ;

!qryMonthlyPric e:
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********@Fort uneJames.com

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

Effective_Da te 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
3483
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: Prices Fields: Inventory #, Price, Effective Year, Effective Month, Effective Day
18
12817
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 received. No biggie, right? Well, here's my problem. I don't know how to tell access to modify everyone's account balance each month. And I can't just always assume that their monthly bill is $16 just because their balance is $16. If I do that...
4
5141
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 invoice records for them in another table, but I have no idea where to begin. Here's the relevant tables: ============== Table: Customer_tbl
1
2921
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 2000. The access file is in access 2000 format. I have a form that will hold the relevent parameters for the query/report that reports the statistics for all job records that match a certain criteria. These are: - A Customer Name.
2
1306
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 I need to select the rate info for that contract where the effective date is <= dateprovided. I need the 1 record that is closest to that date. I am thinking something with max() perhaps. Any ideas? The <= effective
1
4427
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 data is displayed daily. I like to know how I can show the data in weekly and monthly way.so that for the range shown above I would have the monthly or weekly
7
4110
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 monthly series basis. Currently, in excel I am using the weekday and EOMONTH functions to create the flags/indicator in my excel dataset: (Cells in column A contains daily dates)
1
2520
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 events related to the manufacturing process in our company. Everytime a specific event is logged, there is a date mm/dd/yyyy associated with that. What I'm trying to do is do a monthly report that counts the number of individual events within a given...
2
2719
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 that some records have the same value for 'A'. I need to display only 1 checkbox per group of records which has the same attribute 'A'. When the checkbox is checked, I need to update the database for all of the records with the same attribute 'A'. ...
0
9715
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...
0
10603
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10353
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10356
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
9176
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...
1
7643
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
4314
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
3836
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3003
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.