General information
Category:
Databases,Tables, Views, Indexing and SQL syntax
Title:
Dynamic SQL and SQL Server via ODBC connection.
Here is some code I'm fighting with. I want to create or overwrite a table in a SQL Server database. I have a FoxPro (visual 5.0) database (xfile) that includes a connection to the SQL Server database (connection name camextest, SQL Server name CAMEX2000). Any ideas on how to get this to work? I am getting a syntax error on the SELECT statement as this code reads. It matches the syntax in the FoxPro help file.
TIA!
Tom.
***************************
LOCAL cSourceName, cDestName, nCols, cSQLFrom
*-- Make sure we're in the correct directory.
SET DEFAULT TO c:\camex
*-- Open database.
OPEN DATABASE xfile EXCLUSIVE
*-- Open the file that contains all the data
*-- about where to get data and where to put it.
SELECT 0
USE xfile
SET ORDER TO TAG from_table
GO TOP
*-- Walk through the source file, record by record.
DO WHILE !EOF()
nCols = 0
cSourceName = ALLT(xfile.from_table)
cDestName = ALLT(xfile.to_table)
*-- While the record has the same source table name,
*-- process content into an array we can work with.
SCAN WHILE xfile.from_table = cSourceName AND !DELETED()
nCols = nCols + 1
IF nCols = 1
cSQLFrom = ALLT(from_field)
ELSE
cSQLFrom = cSQLFrom + ", " + ALLT(from_field)
ENDIF
ENDSCAN
IF nCols > 0
*-- Select the current destination and source tables.
SELECT 0
USE (cSourceName) SHARED
*-- Add a record to the destination file for each
*-- one in the source file.
SELECT &cSQLFrom FROM &cSourceName WHERE !DELETED() INTO DATABASE CAMEX2000 NAME (cDestName)
ENDIF
SELECT xfile
*-- Make sure the skip doesn't go beyond the end of file and
*-- generate an error.
IF !EOF()
SKIP
ENDIF
ENDDO
*-- Close the database.
CLOSE DATA ALL
Next
Reply
View the map of this thread
View the map of this thread starting from this message only
View all messages of this thread
View all messages of this thread starting from this message only