Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Recordset or tblTemp for aggregating data

Status
Not open for further replies.

hkaing79

Technical User
Jul 26, 2004
234
US
I have a table of data that I would like to remain untouched. From this data, I need to calculate averages disaggregated by various fields. Instead of playing with the WHERE to filter the data, I would like to use SQL to delete those records from a copy of the table.

Using a temporary table, I would make a copy of the table, delete the records using several DELETE statements, then run a SELECT INTO statement to aggregate the data into a table.

I read in other threads that doing so will bloat the database. Instead of copying the table into a temporary table, can I create a copy using DAO recordset, delete the data from the recordset, aggregate the recordset, and then copy the results into a table?

If so, how would I go about working with recordsets?

I guess I'm asking how would I do this (oversimplification):
Function Test()
Dim rs As DAO.Recordset
Set rs = CurrentDb.OpenRecordset("SELECT * FROM tblTest")
CurrentDb.Execute "DELETE FROM " & rs & " WHERE Field4=1"
CurrentDb.Execute "SELECT * INTO tbltmp FROM rs "
End Function
 
Why not just use one SQL statement to do what you want, i.e.
Code:
Function Test()
    CurrentDb.Execute("SELECT tblTest.* INTO YourNewTableNameHere FROM tblTest WHERE tblTest.Field4)<>1")
End Function
Hope this helps.

[pc2]
 
There's a lot of possible filters. Instead of creating a long WHERE expression, I thought it would be easier to just use multiple DELETE statements.

I ended up going the WHERE route, but I'm still curious how to use SQL with recordsets, i.e. SELECT INTO or DELETE.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top