Combining queries using SQL (1 Viewer)

Peter Bellamy

Registered User.
Local time
Today, 17:43
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
 

Trevor G

Registered User.
Local time
Today, 17:43
Joined
Oct 1, 2009
Messages
2,341
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.
 

ghudson

Registered User.
Local time
Today, 12:43
Joined
Jun 8, 2002
Messages
6,194
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.
 

Peter Bellamy

Registered User.
Local time
Today, 17:43
Joined
Dec 3, 2005
Messages
295
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.
 

Peter Bellamy

Registered User.
Local time
Today, 17:43
Joined
Dec 3, 2005
Messages
295
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.
 

dragofly

Registered User.
Local time
Today, 11:43
Joined
Aug 3, 2010
Messages
23
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

Top Bottom