PC SOFT

FORUMS PROFESSIONNELS
WINDEVWEBDEV et WINDEV Mobile

Accueil → WINDEV 2024 → HFSQL query remove duplicate records
HFSQL query remove duplicate records
Débuté par ech madriaga, 12 jan. 2018 22:14 - 5 réponses
Posté le 12 janvier 2018 - 22:14
Hi All,

How to remove or delete the duplicate records in specific column from HFSQL using query?

Or using codes?

Thanks,
Ech
Posté le 13 janvier 2018 - 06:32
Any response please.


Thanks,
Ech
Posté le 13 janvier 2018 - 08:12
Hi, all of your problems with queries could be fixed more easily and much faster if you employ a loop through the file and decide which records to delete and which should stay. WINDEV is a programming language offering a load of H-commands which are designed to fulfill the most complex needs in manipulation of datafiles. Queries are just one way of manipulating a HFSQL datafile, there is no guarantee that all of your needs can be covered by the set of available SQL keywords.

The most simple loop:

HReadFirst(YourFile,YourKey)

while not hout(Yourfile)
.
.
Do whatever you need here ...
.
.
HReadNext(YourFile, YourKey)
END
Posté le 13 janvier 2018 - 08:28
Hi Mit,

Any sample codes to delete the duplicate records in one column.


Thanks,
Posté le 13 janvier 2018 - 09:48
Hi, you store the key of the previous record and if the next record's key is the same then delete it. Where's the problem??
Posté le 13 janvier 2018 - 10:55
Hi Ech,

See what I am doing. The 'Temp...' variables store the values of the current record which I Need to compare for equality. I use a query, just because I filter the data file, don't care about. Next, I never really delete any records in my application, I only mark them as deleted (in German 'Geloescht'). So where I use hmodify you Need to use hdelete.
Hope this helps.

HExecuteQuery(QRY_BuchungStempelDoppelbuchung,hModifyFile,EDT_DatumVon,EDT_DatumBis,EDT_EintragVon,EDT_EintragBis,EDT_AdresseVon,EDT_AdresseBis)
HReadFirst(QRY_BuchungStempelDoppelbuchung)
WHILE NOT HOut
IF nTempOIDMitarbeiter = QRY_BuchungStempelDoppelbuchung.OIDMitarbeiter AND ...
nTempOIDBuchungsart = QRY_BuchungStempelDoppelbuchung.OIDBuchungsart AND ...
nTempAusweisnummer = QRY_BuchungStempelDoppelbuchung.Ausweisnummer AND ...
dtTempZeitpunkt = QRY_BuchungStempelDoppelbuchung.Zeitpunkt AND ...
nTempTerminaladresse = QRY_BuchungStempelDoppelbuchung.Terminaladresse
//
QRY_BuchungStempelDoppelbuchung.Modifiziert = DateSys() + TimeSys()
QRY_BuchungStempelDoppelbuchung.Benutzer = gsBenutzer
QRY_BuchungStempelDoppelbuchung.Geloescht = True
HModify(QRY_BuchungStempelDoppelbuchung)
nAnzahl += 1
STC_Anzahl = "Anzahl: " + nAnzahl
WinRedraw(WIN_DeleteDoppelbuchung)
ELSE
nTempOIDMitarbeiter = QRY_BuchungStempelDoppelbuchung.OIDMitarbeiter
nTempOIDBuchungsart = QRY_BuchungStempelDoppelbuchung.OIDBuchungsart
nTempAusweisnummer = QRY_BuchungStempelDoppelbuchung.Ausweisnummer
dtTempZeitpunkt = QRY_BuchungStempelDoppelbuchung.Zeitpunkt
nTempTerminaladresse = QRY_BuchungStempelDoppelbuchung.Terminaladresse
END
//
HReadNext(QRY_BuchungStempelDoppelbuchung)
END
//

gr

Erik