Autor Beitrag
D. Annies
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1843

windows 7
D6 Enterprise, D7 Pers und TD 2006
BeitragVerfasst: Sa 12.11.11 19:18 
Hi, Delpher,
ich habe mit einer dBase-Tabelle obigen Fehler zur Laufzeit, wenn ich diesen SQL-Befehl verwende:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
SQL.Text := format('select distinct WPK1NAME as WPK from "%s"', [TbSchueler.tablename]) +
                  format(' UNION select WPK2NAME as WPK from "%s"', [TbSchueler.tablename]) +
                  format(' UNION select WPK3NAME as WPK from "%s"', [TbSchueler.tablename]) +
                  format(' UNION select WPK4NAME as WPK from "%s"', [TbSchueler.tablename]);
    Open;


Mit einer FoxProTabelle funktioniert es.
Ich vermute, dass ich ausschließen muss, dass es keine NULL-Felder geben darf. Wie mache ich das?
Wer weiß Rat?
LG, Detlef

_________________
ut vires desint, tamen est laudanda voluntas
D. Annies Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1843

windows 7
D6 Enterprise, D7 Pers und TD 2006
BeitragVerfasst: So 13.11.11 08:05 
Noch kein Erfolg... Kann man "Union" anders ausdrücken?
cu Detlef

_________________
ut vires desint, tamen est laudanda voluntas
mandras
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 434
Erhaltene Danke: 107

Win 10
Delphi 6 Prof, Delphi 10.4 Prof
BeitragVerfasst: So 13.11.11 10:54 
user profile iconD. Annies hat folgendes geschrieben Zum zitierten Posting springen:
Hi, Delpher,
ich habe mit einer dBase-Tabelle obigen Fehler zur Laufzeit, wenn ich diesen SQL-Befehl verwende:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
SQL.Text := format('select distinct WPK1NAME as WPK from "%s"', [TbSchueler.tablename]) +
                  format(' UNION select WPK2NAME as WPK from "%s"', [TbSchueler.tablename]) +
                  format(' UNION select WPK3NAME as WPK from "%s"', [TbSchueler.tablename]) +
                  format(' UNION select WPK4NAME as WPK from "%s"', [TbSchueler.tablename]);
    Open;

Es liegt am "distinct" vermute ich mal (zumindest bei einer Paradox-Tabelle).
Laß das mal weg dann müßten infolge "Union" Duplikate automatisch entfernt werden.

Ansonsten müßte es theoretisch funktionieren die Duplikate per "Group by" zu eliminieren, was aber dann an der langen Ausführungszeit scheitern dürfte (evtl. helfen dagegen korrekte Indexe, das habe ich aber nicht getestet)

Moderiert von user profile iconNarses: Zitat repariert.
D. Annies Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1843

windows 7
D6 Enterprise, D7 Pers und TD 2006
BeitragVerfasst: So 13.11.11 16:12 
Danke, mandras für deine Idee.
Leider habe ich den gleichen Fehler, wenn ich distinct weglasse.
Gruß, Detlef

_________________
ut vires desint, tamen est laudanda voluntas
mandras
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 434
Erhaltene Danke: 107

Win 10
Delphi 6 Prof, Delphi 10.4 Prof
BeitragVerfasst: So 13.11.11 16:21 
sind denn die Felder WPK1NAME bis WPK4NAME wirklich absolut identisch definiert?
D. Annies Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1843

windows 7
D6 Enterprise, D7 Pers und TD 2006
BeitragVerfasst: So 13.11.11 20:47 
UPS !?
Nein, es sind Strings der Länge 71, 43, 65 und 38 - das hatte ich vorher noch nicht bemerkt!

Ist jetzt eine Lösung in Sicht?
LG, Detlef

_________________
ut vires desint, tamen est laudanda voluntas
mandras
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 434
Erhaltene Danke: 107

Win 10
Delphi 6 Prof, Delphi 10.4 Prof
BeitragVerfasst: So 13.11.11 20:54 
Das wird es wohl sein. Ich habe leider grad keine DBASE-Datei zum Prüfen zur Hand..
D. Annies Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1843

windows 7
D6 Enterprise, D7 Pers und TD 2006
BeitragVerfasst: So 13.11.11 21:16 
Hi, mandras, wie muss ich denn vorgehen oder soll ich dein Vorgehen abwarten?
cu, Detlef

_________________
ut vires desint, tamen est laudanda voluntas
mandras
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 434
Erhaltene Danke: 107

Win 10
Delphi 6 Prof, Delphi 10.4 Prof
BeitragVerfasst: So 13.11.11 22:33 
entweder Du änderst die Tabellendefinition so daß alle Felder gleich lang sind oder versuch es einmal so:

SQL.Text := format('select cast (WPK1NAME as varchar(71)) as WPK from "%s"', [TbSchueler.tablename]) +
format(' UNION select cast (WPK2NAME as varchar(71)) as WPK from "%s"', [TbSchueler.tablename]) +
format(' UNION select cast (WPK3NAME as varchar(71)) as WPK from "%s"', [TbSchueler.tablename]) +
format(' UNION select cast (WPK4NAME as varchar(71)) as WPK from "%s"', [TbSchueler.tablename]);

(Hoffe ich habe jetzt keine Fehler eingebaut).

Wie gesagt, ich habe grad keine DBASE-Dateien, mit meinen Paradoxen klappt es.

Für diesen Beitrag haben gedankt: D. Annies
D. Annies Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1843

windows 7
D6 Enterprise, D7 Pers und TD 2006
BeitragVerfasst: Mo 14.11.11 07:48 
Hurra, hurra,
es klappt bestens, ich habe sogar (zur Sicherheit) die Stringlänge für alle auf 75 gesetzt.
Toll, Danke mandras!

_________________
ut vires desint, tamen est laudanda voluntas