TransferDatabase method with WHERE condition

ria.arora

Registered User.
Local time
Today, 08:46
Joined
Jan 25, 2012
Messages
109
Is there any option in the TransferDatabase method which enables you to import selected data? I want import all the recrods before certain date e.g. WHERE Right([BookDate], 4) >= Year(Now) - 1

Please find below the existing code which is bringing everything. I have 6 years data in origional database (approx half million records but I need 2011 and 2012 data. Currently I'm bringing everything and then removing data from which is not efficient. Is there any option to bring only selected data only?
 
Instead of TransfereDatabase why don't you use a Select Into query to import you data Using the IN clause to specify your other DB.

Code:
SELECT * INTO MyImportTable
FROM MyTable IN 'd:\MyFolder\MyOtherDb.mdb'
WHERE Right([BookDate], 4) >= Year(Now) - 1;

A more efficient way whould be to use DateSerial() to set a minumum date that way you don't have to use Right() and Year() functions on every record.

Code:
SELECT * INTO MyImportTable
FROM MyTable IN 'd:\MyFolder\MyOtherDb.mdb'
WHERE [BookDate] > DateSerial(Year(Date) -2, 12, 31);

Provided that [BookDate] is a real Date/Time Field.

Hope this helps.

JR
 

Users who are viewing this thread

Back
Top Bottom