CLOSE ALL CLEAR ALL SET ESCAPE ON *-- ODBC Connection gc_sqlconnect = "MYDSN" *-- Source Table lc_source = "C:\imports\mytable" *-- Target SQL Table lc_target = "mytarget" *-- Target Database gc_database = "MYSQLDB" *-- Connect to SQL Server SET MESSAGE TO "connecting" gnsqlHandle = SQLCONNECT(gc_sqlconnect) = SQLSETPROP(gnsqlHandle, 'Transactions', 2) && Manual transactions = SQLSETPROP(gnsqlHandle, 'asynchronous', .F.) = SQLPREPARE(gnsqlHandle, "USE " + gc_database) ln_exec = SQLEXEC(gnsqlHandle) *-- Zap the target table = SQLPREPARE(gnsqlHandle, "DELETE FROM " + lc_target) ln_exec = SQLEXEC(gnsqlHandle) ld_datetime = DATETIME() lc_time = TIME() *-- Create the insertion command *-- Create the insertion command lc_insertcommand = " INSERT INTO " + lc_target lc_tostring = "(" lc_fromstring = " VALUES (" SELECT 0 USE &lc_source ALIAS a_source SELECT a_source = AFIELDS(la_fields) FOR x = 1 TO ALEN(la_fields)/18 IF UPPER(ALLTRIM(la_fields(x,1))) <> "ID_COL" lc_tostring = lc_tostring + IIF(x =1, "", ", ") + la_fields(x,1) lc_fromstring = lc_fromstring + IIF(x =1, "", ", ") + " ?m." + la_fields(x,1) ENDIF ENDFOR lc_tostring = lc_tostring + ")" lc_fromstring = lc_fromstring + ")" lc_insertcommand = lc_insertcommand + lc_tostring + lc_fromstring SELECT a_source GO TOP SCAN WHILE NOT EOF() SELECT a_source SCATTER MEMVAR MEMO = SQLPREPARE(gnsqlHandle, lc_insertcommand) ln_exec = SQLEXEC(gnsqlHandle) ENDSCAN ln_commit = SQLCOMMIT(gnsqlHandle) && Commit the changes WAIT WINDOW "Conversion Complete" = SQLPREPARE(gnsqlHandle, "SELECT * FROM " + lc_target, "curtarget") ln_exec = SQLEXEC(gnsqlHandle) ln_commit = SQLCOMMIT(gnsqlHandle) && Commit the changes = SQLDISCONNECT(gnsqlHandle) SELECT curtarget GO TOP BROW