D
Dale Peart
This question relates to an earlier post (7/9/04).
I am trying to combine all the records of Table1 with all the results of
Query 1 and Query2. The tables from the queries have some fields that are
not included in Table 1 but need to be included in the result. Also Table1
has columns that are not in the results of the queries.
Because a UNION query requires the same number of columns in each table and
the missing columns in Tables 2 & 3 are padded with "NULL," I get a type
mismatch error when trying to put a "NULL" in the first select statement.
Say field3 does not exist in Query1 and field4 does not exist in Table 1.
'SELECT field1, field2, field3 from Table1 UNION SELECT field1, field2, NULL
from Query1' works fine.
'SELECT field1, field2, field3, field4 from Table1 UNION SELECT field1,
field2, NULL, field4 from Query1' generates a pop-up box requesting input
for field4.
'SELECT field1, field2, field3, NULL from Table1 UNION SELECT field1,
field2, NULL, field4 from Query1' runs for a few seconds and then generates
a "type mismatch" error.
Here is the text of the UNION query that works:
SELECT BotID, ProjectID, FieldID, Site, SampDate, SampTime, LogDate,
SampTyp, Request, Blank, SeqNo, [Weight (g)], Desc, [Referring LabID],
DigestDate, [Dilution Volume], InitialVol FROM [tbl Field Sample Log] UNION
SELECT BotID, ProjectID, NULL, NULL, NULL, NULL, NULL, NULL, NULL, Blank,
NULL, [Weight (g)], NULL, [Referring LabID], DigestDate, NULL, InitialVol
FROM [qry Metal Digestion Combined] UNION SELECT BotID, ProjectID, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, Blank, NULL, [Weight (g)], NULL,
[Referring LabID], DigestDate, NULL, NULL FROM [qry Hg Digestion Combined
Info];
The bottom line is I need to know how to add a field from the result of [qry
Metal Digestion Combined] and/or [qry Hg Digestion Combined Info] that do
not exist in [tbl Field Sample Log]
I know very little about SQL. Is there a solution to this problem?
Dale
I am trying to combine all the records of Table1 with all the results of
Query 1 and Query2. The tables from the queries have some fields that are
not included in Table 1 but need to be included in the result. Also Table1
has columns that are not in the results of the queries.
Because a UNION query requires the same number of columns in each table and
the missing columns in Tables 2 & 3 are padded with "NULL," I get a type
mismatch error when trying to put a "NULL" in the first select statement.
Say field3 does not exist in Query1 and field4 does not exist in Table 1.
'SELECT field1, field2, field3 from Table1 UNION SELECT field1, field2, NULL
from Query1' works fine.
'SELECT field1, field2, field3, field4 from Table1 UNION SELECT field1,
field2, NULL, field4 from Query1' generates a pop-up box requesting input
for field4.
'SELECT field1, field2, field3, NULL from Table1 UNION SELECT field1,
field2, NULL, field4 from Query1' runs for a few seconds and then generates
a "type mismatch" error.
Here is the text of the UNION query that works:
SELECT BotID, ProjectID, FieldID, Site, SampDate, SampTime, LogDate,
SampTyp, Request, Blank, SeqNo, [Weight (g)], Desc, [Referring LabID],
DigestDate, [Dilution Volume], InitialVol FROM [tbl Field Sample Log] UNION
SELECT BotID, ProjectID, NULL, NULL, NULL, NULL, NULL, NULL, NULL, Blank,
NULL, [Weight (g)], NULL, [Referring LabID], DigestDate, NULL, InitialVol
FROM [qry Metal Digestion Combined] UNION SELECT BotID, ProjectID, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, Blank, NULL, [Weight (g)], NULL,
[Referring LabID], DigestDate, NULL, NULL FROM [qry Hg Digestion Combined
Info];
The bottom line is I need to know how to add a field from the result of [qry
Metal Digestion Combined] and/or [qry Hg Digestion Combined Info] that do
not exist in [tbl Field Sample Log]
I know very little about SQL. Is there a solution to this problem?
Dale