Quote:
Originally posted by PJB
don't know if one table would work in this case, what are the possibilities of putting the records into a temp. table at runtime and then extracting the SUMs?
Why not just build a temp table and use code to populate the temp table with the totals? I do this with several reports where SQL is slow, or SQL does not want to total, group, and sum the way I would like. In fact in a database I use a great deal I have a table entitled "Totals" that has several generic ID fields, a date field, one field I call "Typ" and then twenty fields called Cur1, Cur2 etc. I use the "Typ" field to assign a value to the Type of data that the cur Fields contain. When displaying Sales Totals for a user input date range, for example, I assign Typ=20 in the where clause. When totaling a particular item's sales history for a user defined item and date range I use negative ItemNum. I am sure that you get the idea. I can hold totals for a large number of temp totals that are kept in memory until the next time a user looks for that particular total type then I simply use a delete query to delete all records of that Typ before I begin re-total. In several complex Totaling cases I have found that totaling through code can be orders of magnitudes faster than its SQL counter part. (In one example the SQL Query of 135,000 records took close to an hour where the coded counter part took a few moments!) Before you get too excited there are a number of cases where the SQL statments were much faster than the Code. When you are dealing with a large number of records it often pays to try several different methods.