SELECT myTable >DELETE ALL >INDEX ON PADL(SYS(2017, "", 0, 3),10,"0") + PADL(SYS(2017, "", 0, 2),10,"0") to foo.idx UNIQUE >RECALL ALL >SET INDEX TO >* All deleted records are duplicates>
SELECT myTable >ALTER TABLE myTable ADD COLUMN lDelDups l >REPLACE ALL lDelDups with .T. >INDEX ON PADL(SYS(2017, "", 0, 3),10,"0") + PADL(SYS(2017, "", 0, 2),10,"0") to foo.idx UNIQUE >REPLACE ALL lDelDups with .F. >SET INDEX TO >* All records with lDelDups = .T. are duplicates>
>>LPARAMETERS lcFile >> >>*TMT 04/09/13 Now clean up each table of duplicated records >>*start with CHART - text which is the worst >>*Create a temporary Cursor to hold the data from the table >>CREATE CURSOR csrTempTable (col1 C(250), col2 C(250), col3 C(250), col4 C(250), col5 C(250), col6 C(250), col7 C(250), col8 C(250)) >>*Move the Chart text file into the csrTempTable cursor >>lnHandle = FOPEN(lcFile) >>IF lnHandle > 0 >> DO WHILE NOT FEOF(lnHandle) >> lcString = FGETS(lnHandle,2001) && Get the 2000 characters of the string, up to the carriage return >> *Put the string in the row of csrTempTable >> IF NOT EMPTY(lcString) >> APPEND BLANK IN csrTempTable >> REPLACE col1 WITH SUBSTR(lcString,1,250), col2 WITH SUBSTR(lcString,251,250), col3 WITH SUBSTR(lcString,501,250), col4 WITH SUBSTR(lcString,751,250) >> REPLACE col5 WITH SUBSTR(lcString,1001,250), col6 WITH SUBSTR(lcString,1251,250), col7 WITH SUBSTR(lcString,1501,250), col8 WITH SUBSTR(lcString,1751,250) >> ENDIF >> ENDDO >>ENDIF >>FCLOSE(lnHandle) >>*Now UNION it to itself to remove duplicate rows..... >>SELECT * FROM csrTempTable ; >> UNION ; >>SELECT * FROM csrTempTable INTO CURSOR csrDupesRemovedTable >>*Now put this data back into the text file, removing the data from the text file first.... >>DELETE FILE (lcFile) >>lnHandle2 = FCREATE(lcFile) >>SELECT csrDupesRemovedTable >>DO WHILE NOT EOF() >> lcString = col1 + col2 + col3 + col4 + col5 + col6 + col7 + col8 >>*TMT 04/11/2013 - These strings should only by 1600 chars long per BRD >> lcString = LEFT(lcString,1600) >> FPUTS(lnHandle2,lcString) >> SKIP >> lcString = '' >>ENDDO >>FCLOSE(lnHandle2) >>RETURN >>>>