views:

117

answers:

3

I need to export; Multiple queries to different tables of ms access database from ms sql.

I know it is possible by taking each query and export it to a single table and repeating the same for different queries.

What i want to know is... can it be done in one stretch?

suppose there are three queries and each query output need to be in different tables ... in that case is it possible to do with a single export ?

A: 

I'm not sure what you mean. You could put all the SQL statements into one command batch rather than executing each one separately, e.g:

insert into Table1 select ...
insert into Table2 select ...
insert into Table3 select ...
Christian Hayter
suppose there are three queries and each query output need to be in different tables ... in that case is it possible to do with a single export ?
The question is foggy on where this is being run from, but Access/Jet/ACE can't run multiple SQL statements in a batch -- it can only do one at a time. Given the nature of Access/Jet/ACE, i.e., having no server-side process for serializing updates, it should stand to reason that you can't do that (or, at least, you couldn't do it safely and reliably and not be afraid of corrupting your data).
David-W-Fenton
Huh. Every time I look at Access I find another thing it can't do. Thanks David. :-)
Christian Hayter
@David W. Fenton: "run multiple SQL statements in a batch... you can't do that (or, at least, you couldn't do it safely and reliably and not be afraid of corrupting your data)." -- Well, you could use an ADO recordset with batch optimistic locking, add the rows to the recordset then invoke the UpdateBatch method.
onedaywhen
A: 

Are these passthrough queries or Jet (Access) queries? If they are Jet queries, you should create make table queries and run them as a batch through VBA. The make table queries themselves can be constructed easily enough in VBA, if you prefer. Here is an example that gets the connect string from a linked SQL Server table, but you can fill in your own connection string, it should have the same format as the connect property of a linked table.

Dim db As Database
Dim strSQL As String
Dim strConnect As String

Set db = CurrentDb
strConnect = db.TableDefs("dbo_test").Connect

strSQL = "INSERT INTO NewAccessTable (ID, Descr) " _
& "SELECT ID, Descr FROM [" & strConnect & "].[test] "

db.Execute strSQL, dbFailOnError
Debug.Print db.RecordsAffected
Remou
A: 

You can save the individual exports as SSIS packages, then combine them into a single package.

The exports might even be able to run in parallel.

Cade Roux