Nun habe ich aber in der WHERE Klausel nach RES_ID 1260 eingeschränkt und mit einer Unterabfrage wie unten werden ja mehrere Zeilen erzeugt, funktioniert dehalb ja auch nicht. Wie kann ich ohne in der SELECT Abfrage jedesmal die Einschränkung der RES_ID 1260 anzuwenden, die Spalten auslesen.
- Code: Alles auswählen
select TS$_CUSTOMER.CUST_EXT_ID as "R_KDNR"
, '925' as "ORGA"
, case when TS$_HISTORY.RES_ID = 1255 and TS$_HISTORY.CREATOR = 'zyx'
then '54'
when TS$_HISTORY.RES_ID = 1255 and TS$_HISTORY.CREATOR = 'xyz'
then '171'
end as "VTNR"
, TS$_CUSTOMER.CUST_GROUP as "WBWG"
, decode (TS$_SUPPLEMENT_445.NUMR_SPOIA_01,0,'N',1,'Y') as "R_SPOIA_01" --mit Y oder N
, decode (TS$_SUPPLEMENT_445.NUMR_SPSPER_01,0,'N',1,'Y') as "R_SPSPER_01" --Sperren
, '3' as "R_SPHK_01" --immer der 3
, 'GENERELL' as "R_SPKART_01" --immer GENERELL
, '925' as "R_SPORGA_01" --immer 925
, (select case when TS$_HISTORY.CREATOR = 'zyx'
then '54'
when TS$_HISTORY.CREATOR = 'xyz'
then '171'
end
from TS$_HISTORY
where TS$_HISTORY.MAN_ID = 445
and TS$_HISTORY.RES_ID = 1255
) as "R_SPAGNT_01"
, case when TS$_HISTORY.RES_ID = 1260
then to_char (TS$_HISTORY.HIS_CONTACT_END, 'DD.MM.YYYY') else null end as "R_SPDATE_01"
from
TS$_CUSTOMER
, TS$_BANK
, TS$_ADDRESS
, TS$_HISTORY
, TS$_SUPPLEMENT_445
, TS$_TELEPHONE
, (select
max(HIS_ID) as MAX_HIS_ID
from TS$_HISTORY
where 1=1
and MAN_ID = 445
group by MAN_ID, CUST_ID
)MAX_HIS
where 1=1
and TS$_HISTORY.MAN_ID = 445
and TS$_HISTORY.PROJ_ID = 590
and TS$_CUSTOMER.MAN_ID = 445
and TS$_CUSTOMER.MAN_ID = TS$_HISTORY.MAN_ID
and TS$_CUSTOMER.CUST_ID = TS$_HISTORY.CUST_ID
and TS$_CUSTOMER.MAN_ID = TS$_SUPPLEMENT_445.MAN_ID
and TS$_CUSTOMER.CUST_ID = TS$_SUPPLEMENT_445.CUST_ID
and TS$_CUSTOMER.MAN_ID = TS$_TELEPHONE.MAN_ID
and TS$_CUSTOMER.CUST_ID = TS$_TELEPHONE.CUST_ID
and TS$_CUSTOMER.MAN_ID = TS$_BANK.MAN_ID
and TS$_CUSTOMER.CUST_ID = TS$_BANK.CUST_ID
and TS$_CUSTOMER.CUST_ID = TS$_ADDRESS.CUST_ID
and TS$_CUSTOMER.MAN_ID = TS$_ADDRESS.MAN_ID
and TS$_HISTORY.HIS_ID = MAX_HIS.MAX_HIS_ID
and TS$_HISTORY.RES_ID = 1260
order by TS$_CUSTOMER.CUST_EXT_ID
Mit sonnigen und vitaminreichen Grüßen Stefan