Combining queries using SQL

Peter Bellamy

Registered User.
Local time
Today, 00:08
Joined
Dec 3, 2005
Messages
295
If a query is based on two other queries, how is that actioned in vba using SQL?

SQLqry1 = "SELECT....."
SQLqry2 = "SELECT...."

SQLQty3 = ?? (Selecting all the of results of SQLqry1 and SQLqry2)

DoCmd.OpenQuery SQLQry3

Thanks
 
If a query is based on two other queries, how is that actioned in vba using SQL?

SQLqry1 = "SELECT....."
SQLqry2 = "SELECT...."

SQLQty3 = ?? (Selecting all the of results of SQLqry1 and SQLqry2)

DoCmd.OpenQuery SQLQry3

Thanks

Peter,

Query to append records to a temp table, then the same for query 2, then use the Open table to open the temp table.
 
You cannot use a Select query in coded SQL. You will have to used stored queries, not coded SQL if you need to create a table , clear a table or append data to a table if your process needs to run multiple steps. Or you can use action SQLs [delete, create or append] if you want to run the SQL in VBA.

You can use SQL as the record source of a form or report instead of a stored query.
 
I should have said I want to use the resulting query (3) as the where condition in an OpenReport statement for a dynamic report I am creating.
 
I wanted to use SQL as I am opening 10 similar reports based on similar queries.
Just some small text changes in SQL will do this.
I am trying to speed up some old code that uses macros listing the reports, the reports being based on a query that iself is based on a query.
It is the very first query that needs the smalll text changes to provide the other reports.
 
You could use a union query. Something like

Select .... from .... where ....
Union all
select .... from ..... where ....

Which will give you what you want with the fields being named for the first select query.
 

Users who are viewing this thread

Back
Top Bottom