-
Beispiel eines Insert's mit "With" und glaube mir, der läuft seit V5R1:
-- Einfügen Ergebnis des nachfolgenden Select
-- ==========================================
insert into frct
(FCFIRM,
FCWKNR,
FCDATE,
FCSZNR,
FCLANR,
FCRSIA,
FCRSIB,
FCRSIC,
FCRSID,
FCRSEA,
FCRSEB,
FCRSEC,
FCRSED,
FCRSVA,
FCRSVB,
FCRSVC,
FCRSVD,
FCWCI0,
FCWCI1,
FCWCI2,
FCWCI3,
FCWCI4,
FCWCI5,
FCWCE0,
FCWCE1,
FCWCE2,
FCWCE3,
FCWCE4,
FCWCE5,
FCWCV0,
FCWCV1,
FCWCV2,
FCWCV3,
FCWCV4,
FCWCV5
)
-- Zwischenergebnisse, die im eigentlichen Select benötigt werden
with
-- Ermitteln Positionen Rückstand A Status 05 Inland
XPIA (FCRSIA) as
(select count(*) from afp1, kdst
where p1firm=kdfirm and p1wknr=kdwknr
and p1akdn=kdkdnr and p1avsn=kdvenr
and p1st01='05'and kdexkz='I' and p1lanr='D1'
and p1l4da <
year(current date) * 10000 +
month(current date) * 100 +
day(current date)
),
-- Ermitteln Positionen Rückstand A Status 05 Export
XPEA (FCRSEA) as
(select count(*) from afp1, kdst
where p1firm=kdfirm and p1wknr=kdwknr
and p1akdn=kdkdnr and p1avsn=kdvenr
and p1st01='05'and kdexkz='E' and p1lanr='D1'
and p1l4da <
year(current date) * 10000 +
month(current date) * 100 +
day(current date)
),
-- Ermitteln Positionen Rückstand A Status 05 VS
XPVA (FCRSVA) as
(select count(*) from afp1, kdst
where p1firm=kdfirm and p1wknr=kdwknr
and p1akdn=kdkdnr and p1avsn=kdvenr
and p1st01='05'and kdexkz='V' and p1lanr='D1'
and p1l4da <
year(current date) * 10000 +
month(current date) * 100 +
day(current date)
),
-- Ermitteln Positionen Rückstand B Status 12/15 Prio 50/51 Inland
XPIB (FCRSIB) as
(select count(*) from afp1, kdst, lgsl
where p1firm=kdfirm and p1wknr=kdwknr
and p1akdn=kdkdnr and p1avsn=kdvenr
and p1firm=slfirm and p1wknr=slwknr
and p1afnr=slauft and p1afhp=slapos
and (p1st01='12' or P1ST01='15' ) and kdexkz='I' and p1lanr='D1'
and p1l4da <
year(current date) * 10000 +
month(current date) * 100 +
day(current date)
and (slprio=50 or slprio=51) and slstat < '80'
),
-- Ermitteln Positionen Rückstand B Status 12/15 Prio 50/51 Export
XPEB (FCRSEB) as
(select count(*) from afp1, kdst, lgsl
where p1firm=kdfirm and p1wknr=kdwknr
and p1akdn=kdkdnr and p1avsn=kdvenr
and p1firm=slfirm and p1wknr=slwknr
and p1afnr=slauft and p1afhp=slapos
and (p1st01='12' or P1ST01='15' ) and kdexkz='E' and p1lanr='D1'
and p1l4da <
year(current date) * 10000 +
month(current date) * 100 +
day(current date)
and (slprio=50 or slprio=51) and slstat < '80'
),
-- Ermitteln Positionen Rückstand B Status 12/15 Prio 50/51 VS
XPVB (FCRSVB) as
(select count(*) from afp1, kdst, lgsl
where p1firm=kdfirm and p1wknr=kdwknr
and p1akdn=kdkdnr and p1avsn=kdvenr
and p1firm=slfirm and p1wknr=slwknr
and p1afnr=slauft and p1afhp=slapos
and (p1st01='12' or P1ST01='15' ) and kdexkz='V' and p1lanr='D1'
and p1l4da <
year(current date) * 10000 +
month(current date) * 100 +
day(current date)
and (slprio=50 or slprio=51) and slstat < '80'
),
-- Ermitteln Positionen Rückstand C Status 12/15 Prio 40 Inland
XPIC (FCRSIC) as
(select count(*) from afp1, kdst, lgsl
where p1firm=kdfirm and p1wknr=kdwknr
and p1akdn=kdkdnr and p1avsn=kdvenr
and p1firm=slfirm and p1wknr=slwknr
and p1afnr=slauft and p1afhp=slapos
and (p1st01='12' or P1ST01='15' ) and kdexkz='I' and p1lanr='D1'
and p1l4da <
year(current date) * 10000 +
month(current date) * 100 +
day(current date)
and slprio=40
),
-- Ermitteln Positionen Rückstand C Status 12/15 Prio 40 Export
XPEC (FCRSEC) as
(select count(*) from afp1, kdst, lgsl
where p1firm=kdfirm and p1wknr=kdwknr
and p1akdn=kdkdnr and p1avsn=kdvenr
and p1firm=slfirm and p1wknr=slwknr
and p1afnr=slauft and p1afhp=slapos
and (p1st01='12' or P1ST01='15' ) and kdexkz='E' and p1lanr='D1'
and p1l4da <
year(current date) * 10000 +
month(current date) * 100 +
day(current date)
and slprio=40
),
-- Ermitteln Positionen Rückstand C Status 12/15 Prio 40 VS
XPVC (FCRSVC) as
(select count(*) from afp1, kdst, lgsl
where p1firm=kdfirm and p1wknr=kdwknr
and p1akdn=kdkdnr and p1avsn=kdvenr
and p1firm=slfirm and p1wknr=slwknr
and p1afnr=slauft and p1afhp=slapos
and (p1st01='12' or P1ST01='15' ) and kdexkz='V' and p1lanr='D1'
and p1l4da <
year(current date) * 10000 +
month(current date) * 100 +
day(current date)
and slprio=40
),
-- Ermitteln Positionen Rückstand D Status >15 <=40 Inland
XPID (FCRSID) as
(select count(*) from afp1, kdst, lgsl
where p1firm=kdfirm and p1wknr=kdwknr
and p1akdn=kdkdnr and p1avsn=kdvenr
and p1firm=slfirm and p1wknr=slwknr
and p1afnr=slauft and p1afhp=slapos
and p1st01>'15' and P1ST01<='40' and kdexkz='I' and p1lanr='D1'
and p1l4da <
year(current date) * 10000 +
month(current date) * 100 +
day(current date)
),
-- Ermitteln Positionen Rückstand D Status >15 <=40 Export
XPED (FCRSED) as
(select count(*) from afp1, kdst, lgsl
where p1firm=kdfirm and p1wknr=kdwknr
and p1akdn=kdkdnr and p1avsn=kdvenr
and p1firm=slfirm and p1wknr=slwknr
and p1afnr=slauft and p1afhp=slapos
and p1st01>'15' and P1ST01<='40' and kdexkz='E' and p1lanr='D1'
and p1l4da <
year(current date) * 10000 +
month(current date) * 100 +
day(current date)
),
-- Ermitteln Positionen Rückstand D Status >12 <=40 VS
XPVD (FCRSVD) as
(select count(*) from afp1, kdst, lgsl
where p1firm=kdfirm and p1wknr=kdwknr
and p1akdn=kdkdnr and p1avsn=kdvenr
and p1firm=slfirm and p1wknr=slwknr
and p1afnr=slauft and p1afhp=slapos
and p1st01>'15' and P1ST01<='40' and kdexkz='V' and p1lanr='D1'
and p1l4da <
year(current date) * 10000 +
month(current date) * 100 +
day(current date)
),
-- Ermitteln Positionen Aktuelle Woche Status 02/04/05/12 Inland
XPWI0 (FCWCI0) as
(select count(*) from afp1, kdst
where p1firm=kdfirm and p1wknr=kdwknr
and p1akdn=kdkdnr and p1avsn=kdvenr
and p1st01>='02' and P1ST01<='15'
and p1st01<>'03' and kdexkz='I' and p1lanr='D1'
and p1l4da >=year(current date) * 10000 +
month(current date) * 100 +
day(current date)
and p1l4da < year(date(days(current date)+7)) * 10000 +
month(date(days(current date)+7)) * 100 +
day(date(days(current date)+7))
),
-- Ermitteln Positionen +1 Woche Status 02/04/05/12 Inland
XPWI1 (FCWCI1) as
(select count(*) from afp1, kdst
where p1firm=kdfirm and p1wknr=kdwknr
and p1akdn=kdkdnr and p1avsn=kdvenr
and p1st01>='02' and P1ST01<='15'
and p1st01<>'03' and kdexkz='I' and p1lanr='D1'
and p1l4da >=year(date(days(current date)+7)) * 10000 +
month(date(days(current date)+7)) * 100 +
day(date(days(current date)+7))
and p1l4da < year(date(days(current date)+14)) * 10000 +
month(date(days(current date)+14)) * 100 +
day(date(days(current date)+14))
),
-- Ermitteln Positionen +2 Woche Status 02/04/05/12 Inland
XPWI2 (FCWCI2) as
(select count(*) from afp1, kdst
where p1firm=kdfirm and p1wknr=kdwknr
and p1akdn=kdkdnr and p1avsn=kdvenr
and p1st01>='02' and P1ST01<='15'
and p1st01<>'03' and kdexkz='I' and p1lanr='D1'
and p1l4da >=year(date(days(current date)+14)) * 10000 +
month(date(days(current date)+14)) * 100 +
day(date(days(current date)+14))
and p1l4da < year(date(days(current date)+21)) * 10000 +
month(date(days(current date)+21)) * 100 +
day(date(days(current date)+21))
),
-- Ermitteln Positionen +3 Woche Status 02/04/05/12 Inland
XPWI3 (FCWCI3) as
(select count(*) from afp1, kdst
where p1firm=kdfirm and p1wknr=kdwknr
and p1akdn=kdkdnr and p1avsn=kdvenr
and p1st01>='02' and P1ST01<='15'
and p1st01<>'03' and kdexkz='I' and p1lanr='D1'
and p1l4da >=year(date(days(current date)+21)) * 10000 +
month(date(days(current date)+21)) * 100 +
day(date(days(current date)+21))
and p1l4da < year(date(days(current date)+28)) * 10000 +
month(date(days(current date)+28)) * 100 +
day(date(days(current date)+28))
),
-- Ermitteln Positionen +4 Woche Status 02/04/05/12 Inland
XPWI4 (FCWCI4) as
(select count(*) from afp1, kdst
where p1firm=kdfirm and p1wknr=kdwknr
and p1akdn=kdkdnr and p1avsn=kdvenr
and p1st01>='02' and P1ST01<='15'
and p1st01<>'03' and kdexkz='I' and p1lanr='D1'
and p1l4da >=year(date(days(current date)+28)) * 10000 +
month(date(days(current date)+28)) * 100 +
day(date(days(current date)+28))
and p1l4da < year(date(days(current date)+35)) * 10000 +
month(date(days(current date)+35)) * 100 +
day(date(days(current date)+35))
),
-- Ermitteln Positionen >4 Woche Status 02/04/05/12 Inland
XPWI5 (FCWCI5) as
(select count(*) from afp1, kdst
where p1firm=kdfirm and p1wknr=kdwknr
and p1akdn=kdkdnr and p1avsn=kdvenr
and p1st01>='02' and P1ST01<='15'
and p1st01<>'03' and kdexkz='I' and p1lanr='D1'
and p1l4da >=year(date(days(current date)+35)) * 10000 +
month(date(days(current date)+35)) * 100 +
day(date(days(current date)+35))
),
-- Ermitteln Positionen Aktuelle Woche Status 02/04/05/12 Export
XPWE0 (FCWCE0) as
(select count(*) from afp1, kdst
where p1firm=kdfirm and p1wknr=kdwknr
and p1akdn=kdkdnr and p1avsn=kdvenr
and p1st01>='02' and P1ST01<='15'
and p1st01<>'03' and kdexkz='E' and p1lanr='D1'
and p1l4da >=year(current date) * 10000 +
month(current date) * 100 +
day(current date)
and p1l4da < year(date(days(current date)+7)) * 10000 +
month(date(days(current date)+7)) * 100 +
day(date(days(current date)+7))
),
-- Ermitteln Positionen +1 Woche Status 02/04/05/12 Export
XPWE1 (FCWCE1) as
(select count(*) from afp1, kdst
where p1firm=kdfirm and p1wknr=kdwknr
and p1akdn=kdkdnr and p1avsn=kdvenr
and p1st01>='02' and P1ST01<='15'
and p1st01<>'03' and kdexkz='E' and p1lanr='D1'
and p1l4da >=year(date(days(current date)+7)) * 10000 +
month(date(days(current date)+7)) * 100 +
day(date(days(current date)+7))
and p1l4da < year(date(days(current date)+14)) * 10000 +
month(date(days(current date)+14)) * 100 +
day(date(days(current date)+14))
),
-- Ermitteln Positionen +2 Woche Status 02/04/05/12 Export
XPWE2 (FCWCE2) as
(select count(*) from afp1, kdst
where p1firm=kdfirm and p1wknr=kdwknr
and p1akdn=kdkdnr and p1avsn=kdvenr
and p1st01>='02' and P1ST01<='15'
and p1st01<>'03' and kdexkz='E' and p1lanr='D1'
and p1l4da >=year(date(days(current date)+14)) * 10000 +
month(date(days(current date)+14)) * 100 +
day(date(days(current date)+14))
and p1l4da < year(date(days(current date)+21)) * 10000 +
month(date(days(current date)+21)) * 100 +
day(date(days(current date)+21))
),
-- Ermitteln Positionen +3 Woche Status 02/04/05/12 Export
XPWE3 (FCWCE3) as
(select count(*) from afp1, kdst
where p1firm=kdfirm and p1wknr=kdwknr
and p1akdn=kdkdnr and p1avsn=kdvenr
and p1st01>='02' and P1ST01<='15'
and p1st01<>'03' and kdexkz='E' and p1lanr='D1'
and p1l4da >=year(date(days(current date)+21)) * 10000 +
month(date(days(current date)+21)) * 100 +
day(date(days(current date)+21))
and p1l4da < year(date(days(current date)+28)) * 10000 +
month(date(days(current date)+28)) * 100 +
day(date(days(current date)+28))
),
-- Ermitteln Positionen +4 Woche Status 02/04/05/12 Export
XPWE4 (FCWCE4) as
(select count(*) from afp1, kdst
where p1firm=kdfirm and p1wknr=kdwknr
and p1akdn=kdkdnr and p1avsn=kdvenr
and p1st01>='02' and P1ST01<='15'
and p1st01<>'03' and kdexkz='E' and p1lanr='D1'
and p1l4da >=year(date(days(current date)+28)) * 10000 +
month(date(days(current date)+28)) * 100 +
day(date(days(current date)+28))
and p1l4da < year(date(days(current date)+35)) * 10000 +
month(date(days(current date)+35)) * 100 +
day(date(days(current date)+35))
),
-- Ermitteln Positionen >4 Woche Status 02/04/05/12 Export
XPWE5 (FCWCE5) as
(select count(*) from afp1, kdst
where p1firm=kdfirm and p1wknr=kdwknr
and p1akdn=kdkdnr and p1avsn=kdvenr
and p1st01>='02' and P1ST01<='15'
and p1st01<>'03' and kdexkz='E' and p1lanr='D1'
and p1l4da >=year(date(days(current date)+35)) * 10000 +
month(date(days(current date)+35)) * 100 +
day(date(days(current date)+35))
),
-- Ermitteln Positionen Aktuelle Woche Status 02/04/05/12 VS
XPWV0 (FCWCV0) as
(select count(*) from afp1, kdst
where p1firm=kdfirm and p1wknr=kdwknr
and p1akdn=kdkdnr and p1avsn=kdvenr
and p1st01>='02' and P1ST01<='15'
and p1st01<>'03' and kdexkz='V' and p1lanr='D1'
and p1l4da >=year(current date) * 10000 +
month(current date) * 100 +
day(current date)
and p1l4da < year(date(days(current date)+7)) * 10000 +
month(date(days(current date)+7)) * 100 +
day(date(days(current date)+7))
),
-- Ermitteln Positionen +1 Woche Status 02/04/05/12 VS
XPWV1 (FCWCV1) as
(select count(*) from afp1, kdst
where p1firm=kdfirm and p1wknr=kdwknr
and p1akdn=kdkdnr and p1avsn=kdvenr
and p1st01>='02' and P1ST01<='15'
and p1st01<>'03' and kdexkz='V' and p1lanr='D1'
and p1l4da >=year(date(days(current date)+7)) * 10000 +
month(date(days(current date)+7)) * 100 +
day(date(days(current date)+7))
and p1l4da < year(date(days(current date)+14)) * 10000 +
month(date(days(current date)+14)) * 100 +
day(date(days(current date)+14))
),
-- Ermitteln Positionen +2 Woche Status 02/04/05/12 VS
XPWV2 (FCWCV2) as
(select count(*) from afp1, kdst
where p1firm=kdfirm and p1wknr=kdwknr
and p1akdn=kdkdnr and p1avsn=kdvenr
and p1st01>='02' and P1ST01<='15'
and p1st01<>'03' and kdexkz='V' and p1lanr='D1'
and p1l4da >=year(date(days(current date)+14)) * 10000 +
month(date(days(current date)+14)) * 100 +
day(date(days(current date)+14))
and p1l4da < year(date(days(current date)+21)) * 10000 +
month(date(days(current date)+21)) * 100 +
day(date(days(current date)+21))
),
-- Ermitteln Positionen +3 Woche Status 02/04/05/12 VS
XPWV3 (FCWCV3) as
(select count(*) from afp1, kdst
where p1firm=kdfirm and p1wknr=kdwknr
and p1akdn=kdkdnr and p1avsn=kdvenr
and p1st01>='02' and P1ST01<='15'
and p1st01<>'03' and kdexkz='V' and p1lanr='D1'
and p1l4da >=year(date(days(current date)+21)) * 10000 +
month(date(days(current date)+21)) * 100 +
day(date(days(current date)+21))
and p1l4da < year(date(days(current date)+28)) * 10000 +
month(date(days(current date)+28)) * 100 +
day(date(days(current date)+28))
),
-- Ermitteln Positionen +4 Woche Status 02/04/05/12 VS
XPWV4 (FCWCV4) as
(select count(*) from afp1, kdst
where p1firm=kdfirm and p1wknr=kdwknr
and p1akdn=kdkdnr and p1avsn=kdvenr
and p1st01>='02' and P1ST01<='15'
and p1st01<>'03' and kdexkz='V' and p1lanr='D1'
and p1l4da >=year(date(days(current date)+28)) * 10000 +
month(date(days(current date)+28)) * 100 +
day(date(days(current date)+28))
and p1l4da < year(date(days(current date)+35)) * 10000 +
month(date(days(current date)+35)) * 100 +
day(date(days(current date)+35))
),
-- Ermitteln Positionen >4 Woche Status 02/04/05/12 Export
XPWV5 (FCWCV5) as
(select count(*) from afp1, kdst
where p1firm=kdfirm and p1wknr=kdwknr
and p1akdn=kdkdnr and p1avsn=kdvenr
and p1st01>='02' and P1ST01<='15'
and p1st01<>'03' and kdexkz='V' and p1lanr='D1'
and p1l4da >=year(date(days(current date)+35)) * 10000 +
month(date(days(current date)+35)) * 100 +
day(date(days(current date)+35))
),
-- nächste Laufende Nummer
XLFNR (FCFIRM, FCWKNR, FCDATE, FCSZNR, FCLANR) as
(select '2', '001',
year(current date) * 10000 +
month(current date) * 100 +
day(current date), max(FCSZNR) + 1, 'D1'
from frct
where fcfirm='2' and fcwknr='001' and fclanr ='D1'
)
(select '2', '001',
year(current date) * 10000 +
month(current date) * 100 +
day(current date), max(FCSZNR) + 1, 'D1'
from frct
where fcfirm='2' and fcwknr='001' and fclanr ='D1'
)
-- Zusammenführen aller Daten in 1 Zeile
-- =====================================
select * from XLFNR, XPIA, XPIB, XPIC, XPID,
XPEA, XPEB, XPEC, XPED,
XPVA, XPVB, XPVC, XPVD,
XPWI0, XPWI1, XPWI2, XPWI3, XPWI4, XPWI5,
XPWE0, XPWE1, XPWE2, XPWE3, XPWE4, XPWE5,
XPWV0, XPWV1, XPWV2, XPWV3, XPWV4, XPWV5
Similar Threads
-
By KB in forum IBM i Hauptforum
Antworten: 7
Letzter Beitrag: 28-04-16, 15:42
-
By rr2001 in forum IBM i Hauptforum
Antworten: 2
Letzter Beitrag: 07-07-06, 10:56
-
By klausgkv in forum NEWSboard Programmierung
Antworten: 8
Letzter Beitrag: 08-06-06, 14:47
-
By Schorsch in forum NEWSboard Programmierung
Antworten: 2
Letzter Beitrag: 08-09-05, 16:22
-
By Atomik in forum IBM i Hauptforum
Antworten: 1
Letzter Beitrag: 21-11-01, 12:05
Berechtigungen
- Neue Themen erstellen: Nein
- Themen beantworten: Nein
- You may not post attachments
- You may not edit your posts
-
Foren-Regeln
|
Erweiterte Foren Suche
Google Foren Suche
Forum & Artikel Update eMail
AS/400 / IBM i
Server Expert Gruppen
Unternehmens IT
|
Kategorien online Artikel
- Big Data, Analytics, BI, MIS
- Cloud, Social Media, Devices
- DMS, Archivierung, Druck
- ERP + Add-ons, Business Software
- Hochverfügbarkeit
- Human Resources, Personal
- IBM Announcements
- IT-Karikaturen
- Leitartikel
- Load`n`go
- Messen, Veranstaltungen
- NEWSolutions Dossiers
- Programmierung
- Security
- Software Development + Change Mgmt.
- Solutions & Provider
- Speicher – Storage
- Strategische Berichte
- Systemmanagement
- Tools, Hot-Tips
Auf dem Laufenden bleiben
|
Bookmarks