More clarification from you Code Masters Please

J

Jimbo

What if I have more than one query, say for example:
SqlStringA = Transform Query code
SqlStringB = Select Query Code
SqlStringC = Joins SqlStringA and SqlStringB
SqlStringD = Appends SqlStringC to a table

In this case I have four differnt querys, however if I
wanted to write this all in VBA how would I go about that.
I guess my ultimate question is if the case arises, how
would I execute a query in VBA and store the results in
memory to use in a later query also written in VBA?
 
D

Dirk Goldgar

Jimbo said:
What if I have more than one query, say for example:
SqlStringA = Transform Query code
SqlStringB = Select Query Code
SqlStringC = Joins SqlStringA and SqlStringB
SqlStringD = Appends SqlStringC to a table

In this case I have four differnt querys, however if I
wanted to write this all in VBA how would I go about that.
I guess my ultimate question is if the case arises, how
would I execute a query in VBA and store the results in
memory to use in a later query also written in VBA?

I can think of two ways:

1. (Simple but clunky) Save the SQL statements in querydefs (stored
queries) that you create for the purpose, and let each logically
successive querydef refer as needed to the preceding ones. I don't much
like this approach, though.

2. (More elegant, where possible) Combine the SQL statements into one
big one using appropriate syntax and aliases to treat some SQL
statements as "derived tables". Here's a rough example.

INSERT INTO tblOutput
SELECT A.foo, A.bar, B.baz FROM
(SELECT foo, bar FROM tblA
WHERE blah = 'woof') AS A
INNER JOIN
(SELECT DISTINCT bar, baz FROM tblB
WHERE glock = 'spiel') AS B
ON A.bar = B.bar;

Okay, so I don't have a TRANSFORM statement in there. I don't use them
enough to be confident of the syntax.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top