Thema: Delphi SQL-Programmierproblem

Einzelnen Beitrag anzeigen

JesterX

Registriert seit: 25. Jul 2003
Ort: Oldenburg, Niedersachsen
5 Beiträge
 
Delphi 6 Professional
 
#1

SQL-Programmierproblem

  Alt 11. Aug 2003, 09:14
Hallo zusammen,
ich verzweifle an einem SQL-Script.
Ich möchte aus mehreren Tabellen die Werte für jeweils einen Kunden in einer Zeile zusammenfassen. Der Kunde hat zwei Kundennummern. Eine endet auf 9, die andere auf 0.
Abhängig von der Kundennummer sollen die Werte bei 0 in Spalte 1-3 oder bei 9 in Spalte 4-6 angezeigt werden. Hier ist das Skrpit was ich bis jetzt zusammengebracht habe:

SQL-Code:
select ' ',' ',' ',
       to_char(sum(decode (ldtu.ltut_ref, 1001,1,0))),
       to_char(sum(decode (ldtu.ltut_ref, 1007,1,0))),
       to_char(sum(decode (ldtu.ltut_ref, 1024,1,0))),
       substr(ldtu2.lcu_ident,4,4),
       lcust.lcu_name1,
       lcust.lcu_zipcode,
       lcust.lcu_city
from abl_user.ldespatch_tu ldtu, abl_user.ldespatch_tu ldtu2, abl_user.lcust lcust, abl_user.lroute lrou
where ldtu.lrou_ref= lrou.lrou_ref
and ldtu.ldtu_ref = ldtu2.ldtu_ref
and substr(lcust.lcu_ident,-1)='0'
and ldtu2.lcu_ident = lcust.lcu_ident
and to_char(lrou.lrou_departdate,'dd.mm.yyyy') = '04.08.2003'
and lrou.ldz_ident = '220'
group by substr(ldtu2.lcu_ident,4,4),lcust.lcu_name1,lcust.lcu_zipcode,lcust.lcu_city
Union
select to_char(sum(decode (ldtu.ltut_ref, 1001,1,0))),
       to_char(sum(decode (ldtu.ltut_ref, 1007,1,0))),
       to_char(sum(decode (ldtu.ltut_ref, 1024,1,0))),
       ' ',' ',' ',
       substr(ldtu2.lcu_ident,4,4),
       lcust.lcu_name1,
       lcust.lcu_zipcode,
       lcust.lcu_city
from abl_user.ldespatch_tu ldtu, abl_user.ldespatch_tu ldtu2, abl_user.lcust lcust, abl_user.lroute lrou
where ldtu.lrou_ref= lrou.lrou_ref
and ldtu.ldtu_ref = ldtu2.ldtu_ref
and substr(lcust.lcu_ident,-1)='9'
and ldtu2.lcu_ident = lcust.lcu_ident
and to_char(lrou.lrou_departdate,'dd.mm.yyyy') = '04.08.2003'
and lrou.ldz_ident = '220'
group by substr(ldtu2.lcu_ident,4,4),lcust.lcu_name1,lcust.lcu_zipcode,lcust.lcu_city
order by 4
Ich bekomme jedoch immer noch zwei Einträge pro Kunde.
Hat jemand eine Idee?
  Mit Zitat antworten Zitat