Einzelnen Beitrag anzeigen

Ykcim

Registriert seit: 29. Dez 2006
Ort: NRW
799 Beiträge
 
Delphi 10.4 Sydney
 
#11

AW: Fehler bei Left Join

  Alt 13. Sep 2021, 16:10
Das a.zynrefkl='108470001' hat eigentlich nichts in der Abfrage zu suchen. Ich schränke die Abfrage damit nur testweise auf einen Artikel ein. Die Abfrage mit den beiden Selects bringt mir das richtige Ergebnis, aber wenn ich es in mein Delphi-Programm einbaue, bekomme ich eine Fehlermeldung, die ich bis jetzt nicht lösen konnte...:
Erste Gelegenheit für Exception bei $76BBB512. Exception-Klasse EMSSQLNativeException mit Meldung '[FireDAC][Phys][ODBC][Microsoft][SQL Server Native Client 11.0][SQL Server]Incorrect syntax near 'Rückstand'.'. Prozess BD_DHL_Srvr.exe (12540) Ich kann aber nicht erkennen, woran es liegt. Wenn ich den SQL-String in HeidiSQL ausführe, klappt er...

Delphi-Quellcode:
      Query.SQL.Add('SELECT a.zynrefkl AS ' + QuotedStr('Artikelnummer') + ', '+
                             'a.afg_oms1 AS ' + QuotedStr('Artikelbezeichnung 1') + ', '+
                             'concat('+QuotedStr('VPE:')+',a.per__chk,'+QuotedStr(' Stück')+') AS '+QuotedStr('Artikelbezeichnung 2')+' , '+
                             QuotedStr('') +' AS ' + QuotedStr('Artikelbezeichnung 3')+', '+
                             QuotedStr('') +' AS '+QuotedStr('Artikelbezeichnung 4')+', '+
                             QuotedStr('') +' AS '+QuotedStr('Artikelbezeichnung 5')+', '+
                             QuotedStr('') +' AS '+QuotedStr('Artikelbezeichnung 6')+', '+
                             'b.in__vrrd AS ' + QuotedStr('Bestand') + ', '+
                             'a.per__chk AS ' + QuotedStr('Abgreifmenge') + ', '+
                             'a.minstock AS ' + QuotedStr('Mindestbestand') + ', '+
                             'CASE WHEN b.in__vrrd < a.minstock then '+QuotedStr('Mindestmenge unterschritten') + ' ELSE '+QuotedStr('') + ' END AS '+QuotedStr('Bestandskommentar') + ', '+
                             QuotedStr('') + ' AS '+ QuotedStr('Kommentar') + ', '+
                             '(SELECT COALESCE(SUM(c.b_aantal),0) FROM bstlyn__ c '+
                                    'WHERE c.afg__ref=a.afg__ref '+
                                    'AND c.levv_dat<GETDATE() '+
                                    'AND c.lbn__ref = '') AS ' + QuotedStr('Rückstand')+', '+
                             '(SELECT COALESCE(SUM(d.aant_uit),0) FROM hisafg__ d '+
                                    'WHERE d.afg__ref=a.afg__ref) AS '+QuotedStr('Gesamtverbrauch')+' '+
                    ' FROM afgart__ a '+
                    'LEFT JOIN afgant__ b ON b.afg__ref = a.afg__ref '+
                    'LEFT JOIN gegdet__ e on e.det__ref = a.afg__ref and vrg__ref = '+QuotedStr('000002') + ' and tabname_ = '+QuotedStr('afgart__') + ' '+
                    'WHERE a.kla__rpn = '+QuotedStr('MEYLE')+' '+
                    'AND a.zynrefkl <> ' + QuotedStr('') + ' '+
                    'AND (e.antw_txt <> '+ QuotedStr('1')+' '+
                           'or e.antw_txt is null) '+
                    'GROUP BY a.zynrefkl, a.afg_oms1, b.in__vrrd, a.per__chk, a.minstock, a.afg__ref '+
                    'order by a.zynrefkl');
      //Query.ParamByName('Kunde').AsString := 'MEYLE';
      //Query.ParamByName('KZeichenAuslauf').AsString := '1';
      ExecQuery(Query, Cols, Rows, 0);
      //Gesamtverbrauch Stand 12.04.2021 holen
      MyQuery.sql.Add('select * from stand_20210412');
      ExecQuery(MyQuery, MyCols, MyRows, 0);
Keine Ahnung, ich brauch doch nur eine funktionierende Lösung...
Patrick
  Mit Zitat antworten Zitat