Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Import from vfp tables
Message
De
12/05/2008 15:00:54
 
 
À
12/05/2008 05:34:17
Issam Mansour
Jordan Business Machines
Amman, Jordanie
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Import/Export
Versions des environnements
SQL Server:
SQL Server 2005
Divers
Thread ID:
01316356
Message ID:
01316472
Vues:
21
This code will copy any VFP table to a SQL Table with the same format.
If you don't have the table out there, use the upsize wizard.
If you want to add to an existing table, comment out the zap section.
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 
Anyone who does not go overboard- deserves to.
Malcolm Forbes, Sr.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform