Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Retrieving subsets of data using SQL Server cursors
Message
From
14/08/2003 01:59:22
 
General information
Forum:
Visual FoxPro
Category:
Client/server
Miscellaneous
Thread ID:
00819654
Message ID:
00820027
Views:
42
I think I have reconstructed most of the old routine as outlined below. However, I would like to come up with a routine that would work on any SQL table without having to know anything about its contents. The procedure below assumes there is some sort if identifying key column and that I know what it is. I would like a function that accepts only the table name and returns as many dbfs as necessary.
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')
Previous
Reply
Map
View

Click here to load this message in the networking platform