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

How to write query results to a new table with Access 2003

21
Hello!

The reference database I currently use runs queries that pull data from hundreds of tables in order to create user-friendly form view. The problem is that these queries can take upwards of 30 seconds to return.

The solution that I've devised is to create an admin function to cache all these query results and then dump that data into a new, consolidated table, and then have the users search through those new tables. Since our database only changes once a week, this is expected to drastically increase performance and in turn productivity.

The problem is, the admin function that caches the query data and then writes it to the new tables is slow. Very slow.

Here is an example of the current function. This is for one query which returns over 45k results, and takes roughly 45-60 minutes to write out:
Expand|Select|Wrap|Line Numbers
  1. Private Function RefTable()
  2. Dim RefDB As DAO.Database
  3. Dim rs As Recordset
  4.  
  5. Set RefDB as CurrentDB
  6.  
  7. if IsTable("NewTable") then RefDB.Execute "DROP TABLE [NewTable]", dbFailOnError
  8.  
  9. RefDB.Execute "CREATE TABLE NewTable" & _
  10. "(ReferenceID VARCHAR NOT NULL PRIMARY KEY," & _
  11. "Table1 BARCHAR, Table2 VARCHAR, Table3 VARCHAR)"
  12.  
  13. RefDB.TableDefs.Referesh
  14.  
  15. set rs = Recordset
  16.  
  17. 'Pull query results.  This takes about 20 seconds
  18. set rs = RefDB.OpenRecordset("SELECT * from Qry_All_Sources")
  19.  
  20. with rs
  21. if .EOF then exit function
  22.  
  23. .MoveFirst
  24.  
  25. Do Until .EOF
  26.  
  27. RefDB.Execute _
  28. "INSERT INTO NewTable" & _
  29. " (ReferenceID, Table1, Table2, Table3) " & _
  30. "VALUES (" & Chr$(34) & rs![ReferenceID] & Chr$(34) & "," & Chr$(34) & _
  31. rs![Table1] & Chr$(34) & "," & Chr$(34) & rs![Table2] & Chr$(34) & "," & _
  32. Chr$(34) & rs![Table3]  & Chr$(34) & ");"
  33.  
  34. .MoveNext
  35. Loop
  36. End With
  37.  
  38. set rs = Nothing
  39. RefDB.Close
  40. set RefDB = Nothing
  41. End Function
  42.  

Please note, the query takes 20 seconds to pull, but the "INSERT INTO" process takes 30-60 minutes, for just this one query!

This process works, but I would appreciate if someone could tell me a faster or more efficient way to do this. Can data in a recordset be dumped directly into a table? Or is it necessary to go through one record at a time as I'm doing?

Thanks for the help!
May 1 '07 #1
2 3411
Rabbit
12,516 Expert Mod 8TB
You can use an append query for a whole table rather than doing it one record at a time.

It's of the format:
Expand|Select|Wrap|Line Numbers
  1. INSERT INTO TableName (Optional Column List)
  2. SELECT statement;
  3.  
May 1 '07 #2
Hello!

The reference database I currently use runs queries that pull data from hundreds of tables in order to create user-friendly form view. The problem is that these queries can take upwards of 30 seconds to return.

The solution that I've devised is to create an admin function to cache all these query results and then dump that data into a new, consolidated table, and then have the users search through those new tables. Since our database only changes once a week, this is expected to drastically increase performance and in turn productivity.

The problem is, the admin function that caches the query data and then writes it to the new tables is slow. Very slow.

Here is an example of the current function. This is for one query which returns over 45k results, and takes roughly 45-60 minutes to write out:
Expand|Select|Wrap|Line Numbers
  1. Private Function RefTable()
  2. Dim RefDB As DAO.Database
  3. Dim rs As Recordset
  4.  
  5. Set RefDB as CurrentDB
  6.  
  7. if IsTable("NewTable") then RefDB.Execute "DROP TABLE [NewTable]", dbFailOnError
  8.  
  9. RefDB.Execute "CREATE TABLE NewTable" & _
  10. "(ReferenceID VARCHAR NOT NULL PRIMARY KEY," & _
  11. "Table1 BARCHAR, Table2 VARCHAR, Table3 VARCHAR)"
  12.  
  13. RefDB.TableDefs.Referesh
  14.  
  15. set rs = Recordset
  16.  
  17. 'Pull query results.  This takes about 20 seconds
  18. set rs = RefDB.OpenRecordset("SELECT * from Qry_All_Sources")
  19.  
  20. with rs
  21. if .EOF then exit function
  22.  
  23. .MoveFirst
  24.  
  25. Do Until .EOF
  26.  
  27. RefDB.Execute _
  28. "INSERT INTO NewTable" & _
  29. " (ReferenceID, Table1, Table2, Table3) " & _
  30. "VALUES (" & Chr$(34) & rs![ReferenceID] & Chr$(34) & "," & Chr$(34) & _
  31. rs![Table1] & Chr$(34) & "," & Chr$(34) & rs![Table2] & Chr$(34) & "," & _
  32. Chr$(34) & rs![Table3]  & Chr$(34) & ");"
  33.  
  34. .MoveNext
  35. Loop
  36. End With
  37.  
  38. set rs = Nothing
  39. RefDB.Close
  40. set RefDB = Nothing
  41. End Function
  42.  

Please note, the query takes 20 seconds to pull, but the "INSERT INTO" process takes 30-60 minutes, for just this one query!

This process works, but I would appreciate if someone could tell me a faster or more efficient way to do this. Can data in a recordset be dumped directly into a table? Or is it necessary to go through one record at a time as I'm doing?

Thanks for the help!
Himmel,
Did you get your insert query to work?
I have a similar issue and would like to resolve it in the same way. Your assistance would be appreciated.

Thanks for any help

Allan
Feb 15 '08 #3

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

Similar topics

6
by: Mahesh Hardikar | last post by:
Hi , Oracle 8.1.7.0.0 on HP-UX 11.0 I am a newbie as far as PL-SQL is concerned . I have Sybase/MSSQL T-SQL background. We have a report which uses a select statement . This select...
4
by: Surendra | last post by:
I have this query that I need to use in an Update statement to populate a field in the table by the value of Sq ---------------------------------------------------------------------------- Inline...
0
by: nospam1001 | last post by:
Environment is MySQL 3.23.33, PHP Version 4.3.2. Have included a couple of extra columns here in an attempt to clarify what I am trying to do. In the table rid is a unique, auto-increment. The...
9
by: netpurpose | last post by:
I need to extract data from this table to find the lowest prices of each product as of today. The product will be listed/grouped by the name only, discarding the product code - I use...
6
by: Steven D.Arnold | last post by:
I have a query which does not use column indexes that it should use. I have discovered some interesting behaviors of Postgres which may indicate a bug in the database's query planning. Take a...
5
by: deko | last post by:
How to run action query against linked table? I have an Access 2003 mdb with an Excel 2003 Workbook as a linked table. When I attempt to run an action query against the linked table I get this...
10
by: Kenneth | last post by:
I have a Query that consist of a lot of different sales data, and one of the colums are different date. The date goes from 1jan2003 til 31jan2003. in this Query I only want the salesdata for...
4
by: d.p. | last post by:
Hi all, I'm using MS Access 2003. Bare with me on this description....here's the situation: Imagine insurance, and working out premiums for different insured properties. The rates for calculating...
2
by: mmitchell_houston | last post by:
I'm working on a .NET project and I need a single query to return a result set from three related tables in Access 2003, and I'm having trouble getting the results I want. The details: ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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,...
0
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...
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.