Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

[Delphi] SQL-Anweisung funktioniert nicht

Empfohlene Antworten

Veröffentlicht

Hallo Leute,

ich hab hier ein Problem mit meiner SQL-Anweisung. Erstmal der Code:

with DataModuleHDBCMain.HdbcMain.fCreateNewOEQuery do

begin

try

if cbAuswahl.Checked then

sSQL:= 'select LV.ID_LV, LV.Nr_LV, LV.LV_Status as LVStat, LV.Bezeichnung as LVBez, ' +

'LV.Auftrag_Erteilt_Am, LV.Fertigstellung_Bis, ' +

'LV.Baubeginn_Geplant, LV.Auftragssumme, Projekt.Nr_Projekt, ' +

'Projekt.Bezeichnung as ProjBez, LV_Stati.Filter_Programm, LV_Stati.Auftrag_JN, '+

'Objekt.Nr_Objekt, Objekt.Bezeichnung as ObjBez, Adrbaum.Treetext, '+

'V_Baustellenkonto_Crystal.Netto_HW, V_Baustellenkonto_Crystal.Typ, ' +

'GBereich.GBereich_Nr, LV_Stati_Land.Land_ID, LV_Stati_Land.LV_Status, ' +

'(LV.Auftragssumme-V_Baustellenkonto_Crystal.Netto_HW) as Best, ' +

'year(LV.Auftrag_Erteilt_Am) as AJahr, year(LV.Fertigstellung_Bis) ' +

'as FJahr, year(LV.Baubeginn_Geplant) as BJahr, V_Baustellenkonto_Crystal.Rechnung_Zahlung ' +

'from dba.LV, dba.LV_Stati, dba.Projekt, dba.Objekt, dba.GBereich, ' +

'dba. ADRBaum, dba.LV_Stati_Land, dba.V_Baustellenkonto_Crystal ' +

'where LV.LV_Status=LV_Stati.LV_Status_Intern and LV.ID_Objekt=' +

'Objekt.ID_Objekt and LV.ID_Projekt=Projekt.ID_Projekt and ' +

'LV.ID_LV=V_Baustellenkonto_Crystal.ID_LV and ' +

'LV.ID_GBereich=GBereich.ID_GBereich and LV.ID_Auftraggeber='+

'ADRBaum.ID_ADR_Node and LV_Stati.ID_LV_Stati=LV_Stati_Land.ID_LV_Stati ' +

'and not exists (select Rechnung_Zahlung from dba.V_Baustellenkonto_Crystal where ' +

'Rechnung_Zahlung = :sTyp1 and ID_LV=LV.ID_LV) ' +

'and LV_STATI_LAND.LAND_ID = :sLand and V_Baustellenkonto_Crystal.Rechnung_Zahlung= :sTyp2 ' +

'order by Treetext, GBereich.GBereich_Nr, LV.Nr_LV'

else

sSQL:= 'select LV.ID_LV, LV.Nr_LV, LV.LV_Status as LVStat, LV.Bezeichnung as LVBez, ' +

'LV.Auftrag_Erteilt_Am, LV.Fertigstellung_Bis, ' +

'LV.Baubeginn_Geplant, LV.Auftragssumme, Projekt.Nr_Projekt, ' +

'Projekt.Bezeichnung as ProjBez, LV_Stati.Filter_Programm, LV_Stati.Auftrag_JN, '+

'Objekt.Nr_Objekt, Objekt.Bezeichnung as ObjBez, Adrbaum.Treetext, '+

'V_Baustellenkonto_Crystal.Netto_HW, V_Baustellenkonto_Crystal.Typ, ' +

'GBereich.GBereich_Nr, LV_Stati_Land.Land_ID, LV_Stati_Land.LV_Status, ' +

'(LV.Auftragssumme-V_Baustellenkonto_Crystal.Netto_HW) as Best, ' +

'year(LV.Auftrag_Erteilt_Am) as AJahr, year(LV.Fertigstellung_Bis) ' +

'as FJahr, year(LV.Baubeginn_Geplant) as BJahr, V_Baustellenkonto_Crystal.Rechnung_Zahlung ' +

'from dba.LV, dba.LV_Stati, dba.Projekt, dba.Objekt, dba.GBereich, ' +

'dba. ADRBaum, dba.LV_Stati_Land, dba.V_Baustellenkonto_Crystal ' +

'where LV.LV_Status=LV_Stati.LV_Status_Intern and LV.ID_Objekt=' +

'Objekt.ID_Objekt and LV.ID_Projekt=Projekt.ID_Projekt and ' +

'LV.ID_LV=V_Baustellenkonto_Crystal.ID_LV and ' +

'LV.ID_GBereich=GBereich.ID_GBereich and LV.ID_Auftraggeber='+

'ADRBaum.ID_ADR_Node and LV_Stati.ID_LV_Stati=LV_Stati_Land.ID_LV_Stati ' +

'and LV_STATI_LAND.LAND_ID = :sLand ' +

'order by Treetext, GBereich.GBereich_Nr, LV.Nr_LV';

SQL.Add(sSQL);

prepare;

open;

while not eof do

bla bla

finally

Close;

Free;

Folgendes Problem: SQL-Statement Nummer 1 soll immer dann laufen, wenn die Checkbox aktiviert ist, SQL2 im umgekehrten Fall. Wenn ich SQL1 nehme und im Sybase 8.0 über die Datenbank jage bekomme ich 6 Datensaetze. Starte ich das Programm und rufe den zugehörigen Bericht auf erscheint gar nix. Die Variablen sLand, sTyp1 und sTyp2 werden -je nachdem- mit z.B. den Werten 1,'A' und 'R' gefuellt.

Was mach ich falsch?

Bin wie immer dankbar fuer hilfreiche Tips! :)

Saga

Da Saga gerade nicht auf's Board kommt, hab ich das für sie gepostet.

Original geschrieben von "Saga" ;)

Hallo Leute,

ich hab hier ein Problem mit meiner SQL-Anweisung. Erstmal der Code:



with DataModuleHDBCMain.HdbcMain.fCreateNewOEQuery do

  begin

  try

  if cbAuswahl.Checked then

    sSQL:= 'select bla bla '

  else

    sSQL:= 'select bla bla';

  SQL.Add(sSQL);

  prepare;

  open; 


Was mach ich falsch?

Also ich denk mal, dass fCreateNewQuery eine Function ist, die ein TQuery erzeugt und dies dann zurückliefert. Du hast den Databasename beim Query vergessen, ausserdem (wenn du es mit SQL.Add machst) solltest du SQL.Clear nicht vergessen. Ich mach es eigentlich immer mit SQL.Text...

Das wär jetzt das, was mit zuerst aufgefallen ist.

Original geschrieben von MarcG

ausserdem (wenn du es mit SQL.Add machst) solltest du SQL.Clear nicht vergessen.

Ich mach es eigentlich immer mit SQL.Text...

Das steht schon drin. ;) Nach dem Open kommen noch ein paar Variablenzuweisungen, und danach kommt dann auch pflichtgemäß ein Clear hinterher. ;)

Ich probier's mal, danke! :) Sonst noch jemand ne Idee? *in die Runde guck*

Okay, das Problem hat sich mittlerweile erledigt. Er hatte -für mich zwar nicht nachvollziehbar, aber egal- ein Problem mit der Variablenzuweisung. Nu geht's...

Thx for helping. :)

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.