YetAnotherForum
Welcome Guest Search | Active Topics | Log In | Register

How to access data from primary or archive table based on date range. Options
Jason
#1 Posted : Friday, February 19, 2010 3:06:21 PM
Rank: Newbie


Groups: Registered

Joined: 7/13/2009
Posts: 4
Location: Atlanta Ga
I have a table of data that has gotten to big. I am going to archive that table off so that data that is over 2 years old will be saved in a secondary table where it can be accessed but will not put a load on the daily use. Is there a clean way of giving the user an option to use this data without having to join these tables and basically recreate my current problem?
barrob326
#2 Posted : Monday, February 22, 2010 8:58:33 AM
Rank: Member


Groups: Registered

Joined: 7/10/2009
Posts: 21
Location: So California
I had a similar problem as this. I looked at joining the table but the performance was just to slow. The following solution is the most basic, which is you check the date for which you are going to select and base your selection statement on the correct table to fit the date. So more recent dates search the actual table, older dates search the archive table. You have to be accurate with your cut off date with this. The one downfall is that if you do a date range you risk an issue if someone tries to span the dates. That would require a join of the two tables.

Example of selection based on date below.

The selection compares todays date to the date you pass in (From_DateVar) and then decides if it is in the window to select from the new or old data.

IF DateDiff("d",From_DateVar,DateAdd("yyyy",-1, date())) < 0 THEN
sql1 = "SELECT count(Actual_Count) AS BXCount, sum(Actual_1stWt+Actual_2ndWt+Actual_3rdWt) AS Weight FROM Batch WHERE Batch_DateTime >= '" & From_DateVar & " 05:00:00 AM' AND Batch_DateTime <= '" & From_DateVar & " 12:59:00 PM'"
ELSE
sql1 = "SELECT count(Actual_Count) AS BXCount, sum(Actual_1stPowderWt+Actual_2ndPowderWt+Actual_3rdPowderWt) AS Weight FROM Archive_Batch WHERE Batch_DateTime >= '" & From_DateVar & " 05:00:00 AM' AND Batch_DateTime <= '" & From_DateVar & " 12:59:00 PM'"
END IF

Set rs1 = Server.CreateObject("ADODB.Recordset")
rs1.Open sql1, Session("DB_conn")
Please submit any questions or comments through my website.

http://www.qualitysoftwaredesign.com
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

FlatEarth Theme by Jaben Cargman (Tiny Gecko)
Powered by YAF 1.9.3 | YAF © 2003-2009, Yet Another Forum.NET
This page was generated in 0.124 seconds.