Wow.. I think you are going about it the wrong way... Just do a simple SQLCONNECT() to the SQL Database, run a query to the data source, stored procedure, or whatever and it's in a cursor in VFP... Then, you can just "copy" to a DBF and you are done... Something like
lnH = SQLCONNECT()
(dialog pops up for you of ODBC connections).
if not that, you could do
lnH = SQLStringConnect("Provider=... for sql server, server name, etc")
Then
if lnH > 0
sqlexec( lnH, "select * from someTableOnServer where whateverConditon", "C_LocalCursor" )
select C_LocalCursor
copy to PermanentTable
sqldisconnect( lnH )
endif
Now, if there are columns that are longer than 10 character column names, and you are NOT using a database container, you might have to adjust by either changing the query to GET the column names, or re-select the data once local to fit into 10 character non-dbc table context.
Another example to build out the query could be -- for simplicity of readability while typing, I use text/endtext such as
text to lcSQLCmd noshow pretext 1+2
select
t1.Column1,
t1.AVeryLongColumnName as AVLColName,
t1.AnotherLongColumn2 as ALC2,
t1.SomeFlag,
t2.ColumnFromAnotherTable as CFATbl,
t2.AnotherCol
from
SQLDatabase.dbo.SQLTable1 t1
join SQLDatabase.dbo.SQLTable2 t2
on t1.SomeKey = t2.SomeKey
where
t1.SomeCriteria = 'whatever'
order by
t1.SomeFlag
endtext
*/ Then, to "clean up" the string for VFP to pass properly,
*/ strip out the cr/lf from the text such as
lcSQLCmd = chrtran( lcSQLCmd, chr(13)+chr(10), "" )
*/ THEN, pass this command through sqlexec()
sqlexec( lnH, lcSQLCmd, "C_LocalCursor" )
The second is obviously MUCH easier to read what you are trying to get, and notice I've also pre-shortened the long column names to VFP 10 char non-DBC column name limit. Then, just copy out like the first example.