473,396 Members | 1,990 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,396 software developers and data experts.

Create a query in code or not

My application has a table that contains information on buildings. The
building data comes from another database and is imported from a spreadsheet
into my application.

Originally, I thought that when a building data update is available, I would
simply delete the existing data and import the new data into the table.
However, now it seems that there may be a requirement to keep the historical
data.

Of course there is mountains of code now that goes against the building data
table. The table currently is not setup to maintain historical data.

I'm considering the following as a simple fix:

1) Add a data/time field (ImportDate) to the table and the table primary key
which will track the date the building data was imported into my application.

2) Rather than go through and change the code, instead create a query or run
a query everytime the front end opens. The query will simply select all
records from the building data table where ImportDate is the most recent or I
guess I would use MAX.

3) Rename the current building table and name the query with the name that
the building table currently has. That way all code will go against the query
and not the table.

Here's my problem. I've never created a query in code. I'm not even sure if I
have to. I think I can create a query in the dbWindow that just looks for the
maximum Import Date and then gets all records with that date. This would be,
then, the most current data for all buildings. If so, would I need to run the
query explicitly in code or will Access automatically do this every time the
app opens (I think Access will automatically handle this).

Before I spend a lot of time I would like some domments, suggestions, etc.

Thank you.

--
Message posted via http://www.accessmonster.com
Jun 1 '06 #1
1 2605
You're pretty close. Renaming the table and providing a query with the same
name as the old name of the table is a good start.

Purely for performance, you're going to want to do something about that
most-recent-data selection process. Looking for the Max() of your import
date, and then filtering based on that every time you run that query will
take a toll on your performance. In concept, you're correct, but in
practice you can do something once, after you import the data, and improve
your performance.

There are several ways to approach this. Here are a couple:

Add a yes/no field to your data table. Set its default to Yes. Before the
import, run an update query like this:

Update BuildingData Set MostRecent=false where MostRecent=true;

This, of course, means that you're storing information that you could
calculate. In general, this is a no-no. However, it is common to
denormalize for the sake of performance. In this approach, your new query
would simply select records like this:

Select bd.* From BuildingData As bd Where bd.MostRecent=true;

Another approach: Create a "system parameter" table if you don't have one.
Several fields: ParameterKey, ParameterValue_String, ParameterValue_Date,
ParameterValue_Long, etc. as needed. You really only need the date one.
Anyway, after your import you would update like this:

Update ParamTable as pt
Set ParameterValue_Date = (Select Max(ImportDate) From BuildingData;)
Where ParameterValue = 'MostRecentBDImportDate'

That puts your most recent import data on one row in your parameter table.
Then your new query (replacing the table) would select like this:

Select bd.* From BuildingDate as bd Inner Join ParamTable as pt on
bd.ImportDate = pt.ParameterValue_Date;

Hope one of these helps or suggests a solution for you.

Be sure to index ParameterKey as primary key, of course , technically you
might get some benefit from indexing each of the parameter value columns
individually. However, on a table as small as the parameter table I have my
doubts about actual gains being realized from those indexes.
Jun 1 '06 #2

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

Similar topics

1
by: dawnunder | last post by:
eg. Someone fills out 3 fields. (There will be more but this is just to give you an idea) 1. Country? 2. State? 3. City I want this script to generate a web page and list the people by
5
by: lkrubner | last post by:
I have a webserver through Rackspace. I create a domain. I create an FTP user. I upload some files. I create a database called testOfSetupScript and then I create a database user named setup. I...
3
by: Miya | last post by:
I am building a calendar to enter and display training courses. I have a table with the fields CourseID, TrainingDate, TrainingStartTime and TrainingEndTime. Some courses are one day while others...
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,...
3
by: Miguel Dias Moura | last post by:
Hello, I am calling an ASP.NET / VB as follows: search.aspx?search=asp%20book%20london Then I create a string with the keywords like this: Dim keywords() As String =...
5
by: superjacent | last post by:
Hope someone can help. I have a saved parent form containing an unbound sub-form. I set the SourceObject (form) after the Parent Form opens/loads. The sub-form (datasheet view) basically...
4
by: etuncer | last post by:
Hello All, I have Access 2003, and am trying to build a database for my small company. I want to be able to create a word document based on the data entered through a form. the real question is...
3
by: creative1 | last post by:
Here is how you create a complex data report that involves parent and child commands and you can update information at runtime. Its pretty straight forward to work with simple queries; however,...
8
by: Paul H | last post by:
I want to base a form on a crosstab query. The query shows statistics for a user defined period. The column headings will look something like this: ClientID Month01 Month02 Month03 etc.. ...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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:
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,...

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.