Seite 1 von 1

Mitgliedsjahre berechnen

Verfasst: Mo, 22.01.2018 23:57
von benediktlangmantl
Hallo, ich habe folgende Abfrage in Base gemacht

Code: Alles auswählen

SELECT "M_ID", "Name", "Vorname", "Geb-Datum", DATEDIFF( 'yy', "Geb-Datum", CURRENT_DATE ) - CASEWHEN( DAYOFYEAR( "Geb-Datum" ) > DAYOFYEAR( CURRENT_DATE ), 1, 0 ) AS "Alter", "Anrede", "Straße", "PLZ", "Ort", "Land", "Telefon1", "Telefon2", "Telefax", "Telefax", "E-Mail", "Eintritt", "Austritt", DATEDIFF( 'yy', "Eintritt", CURDATE( ) ) AS "Mitgliedsjahre", "Bemerkung", "Foto", "Status" FROM "tbl_Mitglieder"
ich bekomme es hin, die Mitgliedsjahre ausgehend vom Eintrittsdatum zu berechnen. wie muss ich die SQL Ändern, wenn im Feld Austritt etwas steht. Dann soll von Eintrittsdatum bis Austrittsdatum berechnet werden und nicht wie bisher bis heute

Danke schon mal im Voraus aus Berlin

Re: Mitgliedsjahre berechnen

Verfasst: Di, 23.01.2018 15:56
von RobertG
Hallo benediktlangmantl,

Code: Alles auswählen

SELECT "M_ID", "Name", "Vorname", "Geb-Datum", 
DATEDIFF( 'yy', "Geb-Datum", CURRENT_DATE ) - CASEWHEN( DAYOFYEAR( "Geb-Datum" ) > DAYOFYEAR( CURRENT_DATE ), 1, 0 ) AS "Alter", 
"Anrede", "Straße", "PLZ", "Ort", "Land", "Telefon1", "Telefon2", "Telefax", "Telefax", "E-Mail", "Eintritt", "Austritt", 
CASE WHEN "Austritt" IS NULL THEN 
DATEDIFF( 'yy', "Eintritt", CURDATE( ) )
ELSE DATEDIFF( 'yy', "Eintritt", "Austritt" )
END AS "Mitgliedsjahre", "Bemerkung", "Foto", "Status" FROM "tbl_Mitglieder"
Gruß

Robert

Re: Mitgliedsjahre berechnen

Verfasst: Mi, 24.01.2018 01:16
von benediktlangmantl
Vielen Dank RobertG hat super geklappt
Vielen Dank Gruß aus Berlin