Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Import to SQL table from VFP table

Status
Not open for further replies.

whateveragain

Programmer
Apr 20, 2009
92
US
I'm trying to import from a free VFP table on my hard drive. 1) Do I have to be concerned about Ad Hoc Distributed Queries being turned off? 2) What is wrong with the syntax in the following code? I'm getting an error message: Msg 102, Incorrect syntax near ','

Code:
use yeldata

go

Insert into dirmsarf(dircode, msa, poppct, hhldpct, emppct, buspct, whtpct, blkpct, homecode, msacode2)
(select dirmsarf2.dircode, dirmsarf2.msa, dirmsarf2.poppct,
dirmsarf2.hhldpct, dirmsarf2.emppct, dirmsarf2.buspct, dirmsarf2.whtpct, dirmsarf2.blkpct, dirmsarf2.homecode, dirmsarf2.msacode2 from
OPENDATASOURCE('MSDASQL','Driver=Microsoft Visual FoxPro Driver SourceDB=c:\yeldata\Dirmsarf2.dbf;
SourceType=DBF','select * from Dirmsarf2')

Thanks
 
I programmatically changed the Ad Hoc settings to turn enable on then I re-ran the opendatasource and now I'm getting the following errors

If I run the very same code mentioned above: I get the same error message (Incorrect syntax near ').

If I change the code to the following, I get this error: OLE DB provider "MSDASQL" for linked server "(null)" returned message "[Microsoft][ODBC Visual FoxPro Driver]File 'dirmsarf.dbf' does not exist.".
Cannot get the column information from OLE DB provider "MSDASQL" for linked server "(null)".

Code:

SELECT *
FROM OPENROWSET('MSDASQL','Driver={Microsoft FoxPro VFP Driver (*.dbf)};
DBQ=C:\yeldata;
SourceType=DBF',
'SELECT * FROM dirmsarf')
 
Yes, it does exist. I'm wondering if there's another system change I must make.
 
Thanks. I think we're getting closer to the problem. I'm getting a new error. When I import using the wizard, it works except for the column labelled poppct. It should import as a decimal; however, #'s can be whole or decimals 100.00 or .34. All #'s that should be 100 were importing as 0. When importing some tables, I had to change all values to float in order for the correct #'s to import. Changing them within VFP didn't work; it had be be changed within SQL 2008. When I tried your suggestion above, I now get the following error:

Cannot get the current row value of column "[VFPOLEDB.1].poppct" from OLE DB provider "VFPOLEDB.1" for linked server "(null)". The provider cannot determine the value for this column.
 
The difference between SQL Server decimal and VFP numeric formats is that in VFP 5.2 will mean 2 digits before the . and 2 after (the 5 includes the .)

In SQL Server 5.2 will mean 3 and 2.

PluralSight Learning Library
 
That would explain the problem if importing into an already existing table. I was expecting this code to create the table. Am I wrong?
 
I GOT IT WORKING!!!! If I convert the decimal columns to double within VFP, the code above works. Thanks all
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top