lnHandle = SQLSTRINGCONNECT('connect string here') TEXT TO lcCmd TEXTMERGE NOSHOW DECLARE @nNumberOfRecordsPerDBF INT DECLARE @nRecordCount INT SET @nNumberOfRecordsPerDBF = 1000000 SET @nRecordCount = 0 -- Create a temp table to hold key values SELECT PrimaryKey INTO #PKeys FROM BigOleSQLTable WHERE 1 = 2 DEFINE MyCursor CURSOR FOR SELECT PrimaryKey FROM BigOleSQLTable OPEN MyCursor FETCH NEXT FROM MyCursor INTO @primarykey WHILE @@FETCH_STATUS = 0 BEGIN INSERT INTO #PKeys (PrimaryKey) VALUES @primaryKey Set @nRecordCount = @nRecordCount + 1 -- When enough records have been processed, dump them to Foxpro IF @nRecordCount >= @nNumberofRecordsPerDBF BEGIN SELECT a.* FROM BigOleSQLTable a INNER JOIN #PKeys b ON a.PrimaryKey = b.PrimaryKey -- Empty the temp table for next set of records TRUNCATE TABLE #Pkeys @nRecordCount = 0 END -- Get next record FETCH NEXT FROM MyCursor INTO @primarykey END -- Get remaining records SELECT a.* FROM BigOleSQLTable a INNER JOIN #PKeys b ON a.PrimaryKey = b.PrimaryKey CLOSE MyCursor DEALLOCATE MyCursor ENDTEXT lnSuccess = SQLEXEC(lnHandle,lcCmd,'SQLResults')