>How to delete Duplicate Records in VFP

>some times we need to append records manual way from .txt,.xls etc. files
and some records one or more be duplicate so let us see how can we delete it

1st way
CREATE cursor tmp (fld1 n(1), fld2 c(3), fld3 d(8))
INSERT INTO tmp VALUES (1, “AAA”, DATE())
INSERT INTO tmp VALUES (2, “BBB”, DATE())
INSERT INTO tmp VALUES (3, “CCC”, DATE())
INSERT INTO tmp VALUES (1, “AAA”, DATE())
INSERT INTO tmp VALUES (1, “AAA”, DATE())
BROWSE TITLE “duplicates”
SELECT * from tmp UNION ;
SELECT * from tmp INTO CURSOR tmp2 && table
BROWSE TITLE “dupdeleted”

2nd way
Function duplicateDeleter
** procedure to delete duplicate records
** ussing current key field of the default alias ***
**
*!* USAGE : duplicateDeleter(“d:\test2″,”skodu”)
Lparameters tcTable,tcKeyField

Use (m.tcTable) In 0
*-SELECT (m.tcTable)
Set Order To (m.tcKeyField)

Local lcField, lcValue, lcAlias
lcAlias = Alias()
If Empty(lcAlias)
Return
Endif
lcField = Key()
Locate
lcValue = Space(Len(&lcField))
Scan
If lcValue = &lcField
Delete
Loop
Endif
lcValue = &lcField
Endscan

Use In (m.tcTable)

Return
Endfunc

that’s it !

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s