Dear List,
as it seems, MS SQL as used in Access does not allow a select INTO
within a UNION query. Also, it seems that a UNION query can not be used
as a subquery.
Maybe my (simplified) problem can avoid these technicalities: the
original table has columns
A1, A2, B1, B2, C1, C2.
Now, the sum over entries in A1 is taken if the corresponding entries
in A2 satisfy some condition. The same is done for the B- and C-
columns. All those sums should be one single sum, as if the table would
be
F1, F2,
where F2 contains each and all entry/ies from A1, B1, and C1, and F2
those from A2, B2, and C2, and the sum is just taken over those values.
My current solution is like the following UNION-query, with results
saved (by hand) into tbl2.
(SELECT A1 FROM tbl WHERE A2="take me")
UNION ALL
(SELECT B1 FROM tbl WHERE B2="take me")
UNION ALL
(SELECT C1 FROM tbl WHERE C2="take me");
Then, the actual sums are taken by
SELECT SUM(F1) FROM tbl2;
Question 1:
Can the first query use a "SELECT INTO" clause, and if so, where?
Question 2a:
Can the second query use the first one - without the hand-saved
intermediate result?
Question 2b:
If the second query references several fields from the first query,
does Access recompute that first query each time? (A test-query with
ten references has needed about ten times as long.)
Question 3:
Can the two queries be combined into one? Which way is most efficient?
Thanks very much in advance for any advice you can give!
Marco
PS
The data table is quite large, so time IS an issue here. The UNION
query takes about 1.5hrs, and a query referencing the UNION-query about
ten times takes about 15 hours.