Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hallo,
ich habe viele Datensätze die einen Zahlungszeitraum dokumentieren.
z.B. 13.04.2010 bis 05.06.2010
Diesen Zeitraum möchte ich in die jeweiligen Monate aufteilen und dazu die jeweiligen Tage ermitteln.
04.2010 = 18 Tage
05.2010 = 31 Tage
06.2010 = 5 Tage
Hat jemand eine Idee wie ich das bewerkstelligen kann ?
Vielen Dank für die Super Antwort. Ging doch schnell.
Dein Skript funktioniert sehr gut. Leider nicht auf unserem DWH. 😞
Bin ein absoluter Newbie. Hier mein abgewandeltes Skript (es kommt die Meldung: fehlerhafte Syntax):
new_TEMP:
SQL
"id_leistungen",
zahlbis,
zahlvon
FROM
new:
load
zahlbis
,
zahlvon
,
IF(TEXT(DATE(zahlvon,'YYYYMM')) = TEXT(DATE(zahlbis,'YYYYMM')), zahlbis-zahlvon+1, // If Both date within the same Month calc diff between days, plus +1 becaus if DatVon equal DatBis amount should be 1 day
IF(Iterno()=1, MONTHSEND(1, zahlvon) - zahlvon, // Cause Both Dates within different Months, for DatVon calc days till as diff to End of month
IF(TEXT(DATE(ADDMONTHS(zahlvon, iterno() -1, 1), 'YYYYMM')) = TEXT(DATE(zahlbis,'YYYYMM')), DAY(zahlbis), // If last Month just take day of DatBis as amount of days
DAY(MONTHSEND(1, ADDMONTHS(zahlvon, iterno() -1, 1)))
)
)
)
AS AnzahlTage
,
DATE(ADDMonths(zahlvon, iterno() -1, 1), 'MMYYYY') AS MonatJahr
RESIDENT
new_TEMP:
WHILE
;
DROP
TABLEnew_TEMP;
TEXT(DATE(ADDMONTHS(zahlvon, iterno() -1, 1), 'YYYYMM')) <= TEXT(DATE(zahlbis,'YYYYMM'))Gruß
Dirk
Hi,
wenn die Frage in englisch gestellt wird ist die Antwortfrequenz höher und schneller 😉
Schau mal ob das Beispiel anbei passt, Feedback erwünscht 😉
Ist etwas länger, aber damit deckt es auch Zeiträume über Jahresgrenzen hinweg sauber ab. GEht bestimmt noch etwas eleganter, aber denke so passt es erstmal.
Grüße
Michael
tab1:
LOAD * INLINE [
Key, DatVon, DatBis
1, 15.04.2010, 05.06.2010
2, 12.03.2010, 15.03.2010
3, 12.10.2008, 11.02.2010
];
new:
load
Key
, DatVon
, DatBis
, IF(TEXT(DATE(DatVon,'YYYYMM')) = TEXT(DATE(DatBis,'YYYYMM')), DatBis-DatVon+1, // If Both date within the same Month calc diff between days, plus +1 becaus if DatVon equal DatBis amount should be 1 day
IF(Iterno()=1, MONTHSEND(1, DatVon) - DatVon, // Cause Both Dates within different Months, for DatVon calc days till as diff to End of month
IF(TEXT(DATE(ADDMONTHS(DatVon, iterno() -1, 1), 'YYYYMM')) = TEXT(DATE(DatBis,'YYYYMM')), DAY(DatBis), // If last Month just take day of DatBis as amount of days
DAY(MONTHSEND(1, ADDMONTHS(DatVon, iterno() -1, 1)))
)
)
) AS AnzahlTage
, DATE(ADDMonths(DatVon, iterno() -1, 1), 'MMYYYY') AS MonatJahr
RESIDENT
tab1
WHILE TEXT(DATE(ADDMONTHS(DatVon, iterno() -1, 1), 'YYYYMM')) <= TEXT(DATE(DatBis,'YYYYMM'))
;
DROP TABLE tab1;
Vielen Dank für die Super Antwort. Ging doch schnell.
Dein Skript funktioniert sehr gut. Leider nicht auf unserem DWH. 😞
Bin ein absoluter Newbie. Hier mein abgewandeltes Skript (es kommt die Meldung: fehlerhafte Syntax):
new_TEMP:
SQL
"id_leistungen",
zahlbis,
zahlvon
FROM
new:
load
zahlbis
,
zahlvon
,
IF(TEXT(DATE(zahlvon,'YYYYMM')) = TEXT(DATE(zahlbis,'YYYYMM')), zahlbis-zahlvon+1, // If Both date within the same Month calc diff between days, plus +1 becaus if DatVon equal DatBis amount should be 1 day
IF(Iterno()=1, MONTHSEND(1, zahlvon) - zahlvon, // Cause Both Dates within different Months, for DatVon calc days till as diff to End of month
IF(TEXT(DATE(ADDMONTHS(zahlvon, iterno() -1, 1), 'YYYYMM')) = TEXT(DATE(zahlbis,'YYYYMM')), DAY(zahlbis), // If last Month just take day of DatBis as amount of days
DAY(MONTHSEND(1, ADDMONTHS(zahlvon, iterno() -1, 1)))
)
)
)
AS AnzahlTage
,
DATE(ADDMonths(zahlvon, iterno() -1, 1), 'MMYYYY') AS MonatJahr
RESIDENT
new_TEMP:
WHILE
;
DROP
TABLEnew_TEMP;
TEXT(DATE(ADDMONTHS(zahlvon, iterno() -1, 1), 'YYYYMM')) <= TEXT(DATE(zahlbis,'YYYYMM'))Gruß
Dirk
oh, was war das für ein Quatsch, hier nochmal:
new_TEMP:
SQL SELECT
"id_leistungen",
zahlbis,
zahlvon
FROM DWH.dwh.zahlungen;
new:
load "id_leistungen",
zahlbis,
zahlvon
, IF(TEXT(DATE(zahlvon,'YYYYMM')) = TEXT(DATE(zahlbis,'YYYYMM')), zahlbis-zahlvon+1, // If Both date within the same Month calc diff between days, plus +1 becaus if DatVon equal DatBis amount should be 1 day
IF(Iterno()=1, MONTHSEND(1, zahlvon) - zahlvon, // Cause Both Dates within different Months, for DatVon calc days till as diff to End of month
IF(TEXT(DATE(ADDMONTHS(zahlvon, iterno() -1, 1), 'YYYYMM')) = TEXT(DATE(zahlbis,'YYYYMM')), DAY(zahlbis), // If last Month just take day of DatBis as amount of days
DAY(MONTHSEND(1, ADDMONTHS(zahlvon, iterno() -1, 1)))
)
)
) AS AnzahlTage
, DATE(ADDMonths(zahlvon, iterno() -1, 1), 'MMYYYY') AS MonatJahr
RESIDENT
new_TEMP:
WHILE TEXT(DATE(ADDMONTHS(zahlvon, iterno() -1, 1), 'YYYYMM')) <= TEXT(DATE(zahlbis,'YYYYMM'))
;
DROP TABLE new_TEMP;
ich habs:
hinter
RESIDENT new_TEMP war ein : zu viel, der musste weg und es funktioniert !
Danke an Michael.