Einzelnen Beitrag anzeigen

Delphi.Narium

Registriert seit: 27. Nov 2017
2.434 Beiträge
 
Delphi 7 Professional
 
#6

AW: Access SQL Query optimieren?

  Alt 14. Jan 2024, 15:20
Teil Dir das SQL von innen nach außen auf:

Funktioniert das?
SQL-Code:
    select ABFDocAuftragNr, ABFDocDatum, ABFDocKundeKurzbez, ABFDocAuftragID
    from ABFDoc
    where ABFDocOptFertig = false
      and ABFDocVisType = 1
Funktioniert das?
SQL-Code:
    select ABFPosArtNr, ABFPosMenge
    from ABFPos
    where ABFPosEPreis > 0
      and ABFPosType in(0,7)
      and ABFPosNr <> '
      and ABFPosArtNr = :ArtNr
Funktioniert das?
SQL-Code:
select
*
from
(
  (
    select ABFDocAuftragNr, ABFDocDatum, ABFDocKundeKurzbez, ABFDocAuftragID
    from ABFDoc
    where ABFDocOptFertig = false
      and ABFDocVisType = 1
  ) a
  inner join
  (
    select ABFPosArtNr, ABFPosMenge
    from ABFPos
    where ABFPosEPreis > 0
      and ABFPosType in(0,7)
      and ABFPosNr <> '
      and ABFPosArtNr = :ArtNr
  ) b on b.ABFPosAuftragID = a.ABFDocAuftragID
)
Es kann sein, dass Access mit der Art der Schachtelung der Selects nicht zurechtkommt.

Hab' grade mal mit FireBird ein ähnliches Konstrukt hingedaddelt. dort muss vor dem group by das c weg.

Geht es so?
SQL-Code:
select
  ABFDocAuftragNr,
  ABFDocDatum,
  ABFDocKundeKurzbez,
  IIF(Count(ABFDocAuftragID) > 1,Max(ABFPosMenge) - Min(ABFPosMenge), Max(ABFPosMenge)) as offen
from
(
  (
    select ABFDocAuftragNr, ABFDocDatum, ABFDocKundeKurzbez, ABFDocAuftragID
    from ABFDoc
    where ABFDocOptFertig = false
      and ABFDocVisType = 1
  ) a
  inner join
  (
    select ABFPosArtNr, ABFPosMenge
    from ABFPos
    where ABFPosEPreis > 0
      and ABFPosType in(0,7)
      and ABFPosNr <> '
      and ABFPosArtNr = :ArtNr
  ) b on b.ABFPosAuftragID = a.ABFDocAuftragID
)
group by
  ABFDocAuftragNr,
  ABFDocDatum,
  ABFDocKundeKurzbez,
  ABFdocVisType
order by
  ABFDocAuftragNr;
  Mit Zitat antworten Zitat