Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
UNION clause GO BOOM
Message
From
11/04/2013 09:40:56
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
Visual FoxPro
Application:
Desktop
Miscellaneous
Thread ID:
01570728
Message ID:
01570732
Views:
37
To leave the data in the original table without copying to a cursor, maybe try something like:

Using the DELETED mark:
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
Using a temporary field called lDelDups:
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
>Hi Gang!
>
>In getting rid of duplicate records in a table, are there any real world limitations in using the UNION clause in the SQL statement....
>
>like...
>
>
>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 
>
>
>Seems to work fine, but I worry about LARGE tables coming in, and MEMORY problems.......... ever had it to crash this way using UNION ??
>
>Thanks!
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform