9 replies
by dklippert
by borginva
When I do that, I get an error.
I have 2 queries, for example, they are set up to give me the total number of certain sites. The results I get is the count of total sites. Just one figure.
So I build a report using the count field of two queries, and the error I get is:
I have choosen fields from record sources which the wizard can't connect. You may have choosen fields from a table and from a query based on that table. If so, try choosing fields from one table or one query.
The problemis that I do not know how to get one query to give me each seperate's one individual results (say 15 and 34). If you can help with that to make this easier, please let me know.
by jim94539
You probably need a union query. Create a new query but don't select any tables for the query. Then go to the toolbar and select Query / SQL Specific / Union. This opens a window that is waiting for SQL instructions. To combine three separate queries into a single result, the following commands would be needed for a query on a table named "Sites" that contains a field labeled "Name". Name can contain a variety of items that include three base names: Dell, Gateway and Microsoft. Here are the SQL instructions for the union query:
SELECT "Dell" AS Site, Count(Sites.Name) AS [Count]
FROM Sites
WHERE (((Sites.Name) Like "*Dell*"))
UNION ALL SELECT "Gateway" AS Site, Count(Sites.Name) AS [Count]
FROM Sites
WHERE (((Sites.Name) Like "*Gateway*"))
UNION ALL SELECT "Microsoft" AS Site, Count(Sites.Name) AS [Count]
FROM Sites
WHERE (((Sites.Name) Like "*Microsoft*"));
Please notice that the 2nd, 3rd, etc. Select commands start with UNION ALL to connect the statements together. Also, only the last statement ends with a semi-colon. This arrangement can be any length desired as long as each Select statement returns the same number of fields (in this case, two visible and one not visible) and all fields names are identical (in this case, Site and Count for the visible fields and Name for the hidden field created by the Where statement).
- Jim
by borginva
by borginva
by jim94539
Yes, the union query will work with any arrangement of select queries as long as the first is written in a normal fashion (with no semicolon at the end) and each added query starts with Union All. Only the last query statement ends with a semicolon.
Write each query separately using the Access tools. Copy the SQL statements of each into a new Union query and edit it to eliminate the semicolons and add the Union All statements.
The Union query must be created as an SQL query because Access doesn't provide the query builder interface for this special query.
- Jim
by borginva
by borginva
by borginva
This discussion is closed to new replies.
Trending Software posts
Sort by Trending