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: Mo 06.04.09 12:30 
Hi, Delpher,

warum ist der folgende SQL-Befehl falsch? Es gibt kein "Meckern", aber er "Hängt sich auf".

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
SQL.Text := format('select B.Titel, count(*) as Anzahl, B.Klasse, L.Kuerzel ' +
         'from "%s" B, "%s" L ', [TbArtikel.tablename, TbLk.tablename])+
         'where (B.Klasse between ''1%'' and ''9%'') or (B.Klasse = ''DaZ'') ' +
          ' and (B.Klasse = L.Klasse) ' +
         'group by B.Klasse, B.Titel, L.Kuerzel';


Wo sind die Spezis - ich habe keine Ahnung,
Detlef

_________________
ut vires desint, tamen est laudanda voluntas
mkinzler
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 4106
Erhaltene Danke: 13


Delphi 2010 Pro; Delphi.Prism 2011 pro
BeitragVerfasst: Mo 06.04.09 12:51 
Welches DBMS?
Ich würde es mal mit einem expliziten Join versuchen:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
SQL.Text := format('select B.Titel, count(b.ID) as Anzahl, B.Klasse, L.Kuerzel ' +
         'from "%s" B join "%s" L on L.Klasse = B.Klasse ', [TbArtikel.tablename, TbLk.tablename])+
         'where (B.Klasse between ''1%'' and ''9%'') or (B.Klasse = ''DaZ'') '
         'group by B.Klasse, B.Titel, L.Kuerzel;';

Im Allgemeinen würde ich mal über den Einsatz von (SQL-)Parametern nachdenken

_________________
Markus Kinzler.
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 06.04.09 14:20 
Danke, Markus

_________________
ut vires desint, tamen est laudanda voluntas
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Mo 06.04.09 14:24 
In Formatstrings sollte man % escapen (also doppelt schreiben), wenn man ein % im resultierenden String haben möchte.

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
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 06.04.09 19:54 
Danke auch an dich, Benny,
Detlef

_________________
ut vires desint, tamen est laudanda voluntas