|
@@ -0,0 +1,439 @@
|
|
|
+SELECT T3."Auftragsnr_",
|
|
|
+CASE
|
|
|
+WHEN T3."Art" = 1 THEN T3."Menge"
|
|
|
+ELSE 0
|
|
|
+END,
|
|
|
+CASE
|
|
|
+WHEN T3."Nr_" NOT like 'HU-K%'
|
|
|
+AND T3."Produktbuchungsgruppe" NOT IN ('W_DP')
|
|
|
+AND T3."Nr_" NOT IN ('E002540') THEN T3."Menge (Stunde)"
|
|
|
+ELSE 0
|
|
|
+END,
|
|
|
+CASE
|
|
|
+WHEN T3."Produktbuchungsgruppe" NOT IN (
|
|
|
+'W_KARO',
|
|
|
+'W_MECH',
|
|
|
+'W_LACK',
|
|
|
+'W_KARO_AZK',
|
|
|
+'W_LACK_AZE',
|
|
|
+'W_ELEK',
|
|
|
+'W_ELEK_NL',
|
|
|
+'W_KARO_NL',
|
|
|
+'W_LACK_NL',
|
|
|
+'W_MECH_NL',
|
|
|
+'W_SATT'
|
|
|
+)
|
|
|
+AND T3."Produktbuchungsgruppe" NOT like 'T\_%' escape '\' or T3."Nr_" = ' E002540 ' THEN CASE WHEN case WHEN(T3."Geschäftsbuchungsgruppe"IN (' C_INTERN ',' INTERN ',' P_INTERN ')) THEN ' Intern '
|
|
|
+ WHEN(T3."Geschäftsbuchungsgruppe"IN (' GAR_NST ',' GAR_STB ')) THEN ' GWL '
|
|
|
+ ELSE ' Extern '
|
|
|
+ END = ' Intern ' THEN T3."Verrechnungsbetrag"
|
|
|
+ ELSE CASE WHEN T3."Offen" = 0 THEN T3."Verkaufsbetrag" * -1
|
|
|
+ ELSE T3."Verkaufsbetrag"
|
|
|
+ END
|
|
|
+ END
|
|
|
+ ELSE 0
|
|
|
+ END , CASE WHEN case WHEN T3."Produktbuchungsgruppe" like ' T \ _ % ' escape ' \ ' THEN T3."Einstandsbetrag"
|
|
|
+ ELSE 0
|
|
|
+ END = 0 AND CASE WHEN(T3."Produktbuchungsgruppe"IN (' W_KARO ',' W_MECH ',' W_LACK ',' W_KARO_AZK ',' W_LACK_AZE ',' W_ELEK ',' W_ELEK_NL ',' W_KARO_NL ',' W_LACK_NL ',' W_MECH_NL ',' W_SATT ')
|
|
|
+ AND T3."Nr_" <> ' E002540 ') THEN CASE WHEN(case WHEN(T3."Geschäftsbuchungsgruppe"IN (' C_INTERN ',' INTERN ',' P_INTERN ')) THEN ' Intern '
|
|
|
+ WHEN(T3."Geschäftsbuchungsgruppe"IN (' GAR_NST ',' GAR_STB ')) THEN ' GWL '
|
|
|
+ ELSE ' Extern '
|
|
|
+ END = ' Intern ') THEN T3."Verrechnungsbetrag"
|
|
|
+ ELSE CASE WHEN(T3."Offen" = 0) THEN T3."Verkaufsbetrag" * -1
|
|
|
+ ELSE T3."Verkaufsbetrag"
|
|
|
+ END
|
|
|
+ END
|
|
|
+ ELSE 0
|
|
|
+ END = 0 AND CASE WHEN(T3."Produktbuchungsgruppe" like ' T \ _ % ' escape ' \ '
|
|
|
+ AND T3."Nr_" <> ' E002540 ') THEN CASE WHEN(case WHEN(T3."Geschäftsbuchungsgruppe"IN (' C_INTERN ',' INTERN ',' P_INTERN ')) THEN ' Intern '
|
|
|
+ WHEN(T3."Geschäftsbuchungsgruppe"IN (' GAR_NST ',' GAR_STB ')) THEN ' GWL '
|
|
|
+ ELSE ' Extern '
|
|
|
+ END = ' Intern ') THEN T3."Verrechnungsbetrag"
|
|
|
+ ELSE CASE WHEN(T3."Offen" = 0) THEN T3."Verkaufsbetrag" * -1
|
|
|
+ ELSE T3."Verkaufsbetrag"
|
|
|
+ END
|
|
|
+ END
|
|
|
+ ELSE 0
|
|
|
+ END <> 0 THEN T3."Menge" * T8."Einstandspreis"
|
|
|
+ ELSE CASE WHEN T3."Produktbuchungsgruppe" like ' T \ _ % ' escape ' \ ' THEN T3."Einstandsbetrag"
|
|
|
+ ELSE 0
|
|
|
+ END
|
|
|
+ END , CASE WHEN T3."Produktbuchungsgruppe" like ' T \ _ % ' escape ' \ ' AND T3."Nr_" <> ' E002540 ' THEN CASE WHEN case WHEN(T3."Geschäftsbuchungsgruppe"IN (' C_INTERN ',' INTERN ',' P_INTERN ')) THEN ' Intern '
|
|
|
+ WHEN(T3."Geschäftsbuchungsgruppe"IN (' GAR_NST ',' GAR_STB ')) THEN ' GWL '
|
|
|
+ ELSE ' Extern '
|
|
|
+ END = ' Intern ' THEN T3."Verrechnungsbetrag"
|
|
|
+ ELSE CASE WHEN T3."Offen" = 0 THEN T3."Verkaufsbetrag" * -1
|
|
|
+ ELSE T3."Verkaufsbetrag"
|
|
|
+ END
|
|
|
+ END
|
|
|
+ ELSE 0
|
|
|
+ END , CASE WHEN T3."Produktbuchungsgruppe" IN (' W_KARO ',' W_MECH ',' W_LACK ',' W_KARO_AZK ',' W_LACK_AZE ',' W_ELEK ',' W_ELEK_NL ',' W_KARO_NL ',' W_LACK_NL ',' W_MECH_NL ',' W_SATT ') AND T3."Nr_" <> ' E002540 ' THEN CASE WHEN case WHEN(T3."Geschäftsbuchungsgruppe"IN (' C_INTERN ',' INTERN ',' P_INTERN ')) THEN ' Intern '
|
|
|
+ WHEN(T3."Geschäftsbuchungsgruppe"IN (' GAR_NST ',' GAR_STB ')) THEN ' GWL '
|
|
|
+ ELSE ' Extern '
|
|
|
+ END = ' Intern ' THEN T3."Verrechnungsbetrag"
|
|
|
+ ELSE CASE WHEN T3."Offen" = 0 THEN T3."Verkaufsbetrag" * -1
|
|
|
+ ELSE T3."Verkaufsbetrag"
|
|
|
+ END
|
|
|
+ END
|
|
|
+ ELSE 0
|
|
|
+ END , CASE WHEN case WHEN(T3."Produktbuchungsgruppe" like ' T \ _ % ' escape ' \ '
|
|
|
+ AND T3."Nr_" <> ' E002540 ') THEN CASE WHEN(case WHEN(T3."Geschäftsbuchungsgruppe"IN (' C_INTERN ',' INTERN ',' P_INTERN ')) THEN ' Intern '
|
|
|
+ WHEN(T3."Geschäftsbuchungsgruppe"IN (' GAR_NST ',' GAR_STB ')) THEN ' GWL '
|
|
|
+ ELSE ' Extern '
|
|
|
+ END = ' Intern ') THEN T3."Verrechnungsbetrag"
|
|
|
+ ELSE CASE WHEN(T3."Offen" = 0) THEN T3."Verkaufsbetrag" * -1
|
|
|
+ ELSE T3."Verkaufsbetrag"
|
|
|
+ END
|
|
|
+ END
|
|
|
+ ELSE 0
|
|
|
+ END - CASE WHEN(case WHEN T3."Produktbuchungsgruppe" like ' T \ _ % ' escape ' \ ' THEN T3."Einstandsbetrag"
|
|
|
+ ELSE 0
|
|
|
+ END = 0
|
|
|
+ AND CASE WHEN(T3."Produktbuchungsgruppe"IN (' W_KARO ',' W_MECH ',' W_LACK ',' W_KARO_AZK ',' W_LACK_AZE ',' W_ELEK ',' W_ELEK_NL ',' W_KARO_NL ',' W_LACK_NL ',' W_MECH_NL ',' W_SATT ')
|
|
|
+ AND T3."Nr_" <> ' E002540 ') THEN CASE WHEN(case WHEN(T3."Geschäftsbuchungsgruppe"IN (' C_INTERN ',' INTERN ',' P_INTERN ')) THEN ' Intern '
|
|
|
+ WHEN(T3."Geschäftsbuchungsgruppe"IN (' GAR_NST ',' GAR_STB ')) THEN ' GWL '
|
|
|
+ ELSE ' Extern '
|
|
|
+ END = ' Intern ') THEN T3."Verrechnungsbetrag"
|
|
|
+ ELSE CASE WHEN(T3."Offen" = 0) THEN T3."Verkaufsbetrag" * -1
|
|
|
+ ELSE T3."Verkaufsbetrag"
|
|
|
+ END
|
|
|
+ END
|
|
|
+ ELSE 0
|
|
|
+ END = 0
|
|
|
+ AND CASE WHEN(T3."Produktbuchungsgruppe" like ' T \ _ % ' escape ' \ '
|
|
|
+ AND T3."Nr_" <> ' E002540 ') THEN CASE WHEN(case WHEN(T3."Geschäftsbuchungsgruppe"IN (' C_INTERN ',' INTERN ',' P_INTERN ')) THEN ' Intern '
|
|
|
+ WHEN(T3."Geschäftsbuchungsgruppe"IN (' GAR_NST ',' GAR_STB ')) THEN ' GWL '
|
|
|
+ ELSE ' Extern '
|
|
|
+ END = ' Intern ') THEN T3."Verrechnungsbetrag"
|
|
|
+ ELSE CASE WHEN(T3."Offen" = 0) THEN T3."Verkaufsbetrag" * -1
|
|
|
+ ELSE T3."Verkaufsbetrag"
|
|
|
+ END
|
|
|
+ END
|
|
|
+ ELSE 0
|
|
|
+ END <> 0) THEN T3."Menge" * T8."Einstandspreis"
|
|
|
+ ELSE CASE WHEN T3."Produktbuchungsgruppe" like ' T \ _ % ' escape ' \ ' THEN T3."Einstandsbetrag"
|
|
|
+ ELSE 0
|
|
|
+ END
|
|
|
+ END < 0 THEN ' VK < EK '
|
|
|
+ ELSE ' VK > EK '
|
|
|
+ END , CASE WHEN T3."Produktbuchungsgruppe" like ' % LOHN % ' THEN T3."Produktbuchungsgruppe"
|
|
|
+ ELSE NULL
|
|
|
+ END ,
|
|
|
+T8."Nr_"
|
|
|
+,
|
|
|
+T8."GMPD Code" + T8."GMPD Subcode"
|
|
|
+,
|
|
|
+T8."GMPD Subcode"
|
|
|
+,
|
|
|
+T8."GMPD Code"
|
|
|
+,
|
|
|
+T7."Erstzulassung"
|
|
|
+, CASE WHEN T1."Buchungsdatum" is null THEN T2."Buchungsdatum"
|
|
|
+ELSE T1."Buchungsdatum"
|
|
|
+END ,
|
|
|
+T6."PLZ Code"
|
|
|
+,
|
|
|
+substring(T6."PLZ Code",1,4) ,
|
|
|
+substring(T6."PLZ Code",1,3) ,
|
|
|
+substring(T6."PLZ Code",1,2) ,
|
|
|
+substring(T6."PLZ Code",1,1) , CASE WHEN T10."Ländercode" is null or T10."Ländercode" = ' ' or T10."Ländercode" IN (' D ',' DE ') THEN ' Deutschland '
|
|
|
+ ELSE ' Ausland '
|
|
|
+END ,
|
|
|
+T6."Ländercode"
|
|
|
+,
|
|
|
+T6."Nr_" + ' - ' + T6."Name"
|
|
|
+,
|
|
|
+T3."Geschäftsbuchungsgruppe"
|
|
|
+,
|
|
|
+substring(upper(T7."Modell") ,1,3) ,
|
|
|
+T3."Markencode"
|
|
|
+, CASE WHEN T3."Markencode" IN (' OPEL ',' VW ') THEN T3."Markencode"
|
|
|
+ELSE ' Fremdfabrikat '
|
|
|
+END ,
|
|
|
+T3."Kostenstellencode" + ' - ' + T9."Name"
|
|
|
+,
|
|
|
+getdate() , CASE WHEN T1."Nr_" is null THEN T2."Nr_"
|
|
|
+ELSE T1."Nr_"
|
|
|
+END + ' - ' + CASE WHEN NOT T5."Nachname" is null or T5."Nachname" <> '' THEN T3."Serviceberaternr_" + ' - ' + T5."Vorname" + ' ' + T5."Nachname"
|
|
|
+ELSE ' SB fehlt '
|
|
|
+END + ' - ' + T6."Nr_" + ' - ' + T6."Name" , CASE WHEN T1."Nr_" is null THEN T2."Nr_"
|
|
|
+ ELSE T1."Nr_"
|
|
|
+END + ' - ' + T6."Name" , CASE WHEN T3."Geschäftsbuchungsgruppe" IN (' C_INTERN ',' INTERN ',' P_INTERN ') THEN ' Intern '
|
|
|
+ WHEN T3."Geschäftsbuchungsgruppe" IN (' GAR_NST ',' GAR_STB ') THEN ' GWL '
|
|
|
+ ELSE ' Extern '
|
|
|
+ END , CASE WHEN NOT T5."Nachname" is null or T5."Nachname" <> '' THEN T3."Serviceberaternr_" + ' - ' + T5."Vorname" + ' ' + T5."Nachname"
|
|
|
+ ELSE ' SB fehlt '
|
|
|
+ END , CASE WHEN T1."Filialcode" is null THEN T2."Filialcode"
|
|
|
+ ELSE T1."Filialcode"
|
|
|
+ END , CASE WHEN T5."Funktion" IN (' Service Berater ',' Serviceberater ',' Serviceverater ') THEN ' Serviceberater '
|
|
|
+ ELSE ' sonstige MA '
|
|
|
+ END ,
|
|
|
+T5."Funktion"
|
|
|
+,
|
|
|
+T3."Herkunftsnr_(Zahlung)"
|
|
|
+,
|
|
|
+T1."Rech_ an Name"
|
|
|
+,
|
|
|
+T1."Rech_ an Deb_-Nr_"
|
|
|
+, CASE WHEN T1."Auftragsdatum" is null THEN T2."Auftragsdatum"
|
|
|
+ELSE T1."Auftragsdatum"
|
|
|
+END , CASE WHEN T1."Nr_" is null THEN T2."Nr_"
|
|
|
+ELSE T1."Nr_"
|
|
|
+END + ' - ' + T6."Name" + ' - ' + CASE WHEN NOT T5."Nachname" is null or T5."Nachname" <> '' THEN T3."Serviceberaternr_" + ' - ' + T5."Vorname" + ' ' + T5."Nachname"
|
|
|
+ ELSE ' SB fehlt '
|
|
|
+END + ' - ' ,
|
|
|
+datepart(weekday,getdate()) ,
|
|
|
+T8."Einstandspreis (durchschn_)"
|
|
|
+,
|
|
|
+T8."EK-Preis (neuester)"
|
|
|
+,
|
|
|
+T8."Einstandspreis"
|
|
|
+,
|
|
|
+T8."VK-Preis"
|
|
|
+,
|
|
|
+T8."Basiseinheitencode"
|
|
|
+,
|
|
|
+T8."Beschreibung"
|
|
|
+,
|
|
|
+T3."Verrechnungsbetrag"
|
|
|
+, CASE WHEN(T3."Produktbuchungsgruppe" like ' T \ _ % ' escape ' \ '
|
|
|
+AND T3."Nr_" <> ' E002540 ') THEN CASE WHEN(case WHEN(T3."Geschäftsbuchungsgruppe"IN (' C_INTERN ',' INTERN ',' P_INTERN ')) THEN ' Intern '
|
|
|
+WHEN(T3."Geschäftsbuchungsgruppe"IN (' GAR_NST ',' GAR_STB ')) THEN ' GWL '
|
|
|
+ ELSE ' Extern '
|
|
|
+END = ' Intern ') THEN T3."Verrechnungsbetrag"
|
|
|
+ELSE CASE WHEN(T3."Offen" = 0) THEN T3."Verkaufsbetrag" * -1
|
|
|
+ ELSE T3."Verkaufsbetrag"
|
|
|
+END
|
|
|
+END
|
|
|
+ ELSE 0
|
|
|
+END - CASE WHEN(case WHEN T3."Produktbuchungsgruppe" like ' T \ _ % ' escape ' \ ' THEN T3."Einstandsbetrag"
|
|
|
+ELSE 0
|
|
|
+END = 0
|
|
|
+AND CASE WHEN(T3."Produktbuchungsgruppe"IN (' W_KARO ',' W_MECH ',' W_LACK ',' W_KARO_AZK ',' W_LACK_AZE ',' W_ELEK ',' W_ELEK_NL ',' W_KARO_NL ',' W_LACK_NL ',' W_MECH_NL ',' W_SATT ')
|
|
|
+AND T3."Nr_" <> ' E002540 ') THEN CASE WHEN(case WHEN(T3."Geschäftsbuchungsgruppe"IN (' C_INTERN ',' INTERN ',' P_INTERN ')) THEN ' Intern '
|
|
|
+WHEN(T3."Geschäftsbuchungsgruppe"IN (' GAR_NST ',' GAR_STB ')) THEN ' GWL '
|
|
|
+ ELSE ' Extern '
|
|
|
+END = ' Intern ') THEN T3."Verrechnungsbetrag"
|
|
|
+ ELSE CASE WHEN(T3."Offen" = 0) THEN T3."Verkaufsbetrag" * -1
|
|
|
+ ELSE T3."Verkaufsbetrag"
|
|
|
+ END
|
|
|
+END
|
|
|
+ ELSE 0
|
|
|
+END = 0
|
|
|
+AND CASE WHEN(T3."Produktbuchungsgruppe" like ' T \ _ % ' escape ' \ '
|
|
|
+AND T3."Nr_" <> ' E002540 ') THEN CASE WHEN(case WHEN(T3."Geschäftsbuchungsgruppe"IN (' C_INTERN ',' INTERN ',' P_INTERN ')) THEN ' Intern '
|
|
|
+WHEN(T3."Geschäftsbuchungsgruppe"IN (' GAR_NST ',' GAR_STB ')) THEN ' GWL '
|
|
|
+ ELSE ' Extern '
|
|
|
+END = ' Intern ') THEN T3."Verrechnungsbetrag"
|
|
|
+ ELSE CASE WHEN(T3."Offen" = 0) THEN T3."Verkaufsbetrag" * -1
|
|
|
+ ELSE T3."Verkaufsbetrag"
|
|
|
+ END
|
|
|
+END
|
|
|
+ ELSE 0
|
|
|
+END <> 0) THEN T3."Menge" * T8."Einstandspreis"
|
|
|
+ELSE CASE WHEN T3."Produktbuchungsgruppe" like ' T \ _ % ' escape ' \ ' THEN T3."Einstandsbetrag"
|
|
|
+ ELSE 0
|
|
|
+END
|
|
|
+END ,
|
|
|
+T3."Kundengruppencode"
|
|
|
+,
|
|
|
+T1."Archivierungsdatum"
|
|
|
+, CASE WHEN T3."Menge pro Stunde" <> 0 THEN convert(float(53) ,(T3."AW Mont_ 1" + T3."AW Mont_ 2")) / T3."Menge pro Stunde"
|
|
|
+ELSE T3."AW Mont_ 1" + T3."AW Mont_ 2"
|
|
|
+END , CASE WHEN T3."Menge pro Stunde" <> 0 AND CASE WHEN(T3."Nr_" NOT like ' HU - K % '
|
|
|
+AND T3."Produktbuchungsgruppe" NOT IN (' W_DP ')
|
|
|
+AND T3."Nr_" NOT IN (' E002540 ')) THEN T3."Menge (Stunde)"
|
|
|
+ ELSE 0
|
|
|
+END >= 0 AND T3."Nr_" NOT like ' HU - K % ' THEN convert(float(53) ,T3."Vorgabezeit") / T3."Menge pro Stunde"
|
|
|
+WHEN T3."Menge pro Stunde" <> 0 AND CASE WHEN(T3."Nr_" NOT like ' HU - K % '
|
|
|
+AND T3."Produktbuchungsgruppe" NOT IN (' W_DP ')
|
|
|
+AND T3."Nr_" NOT IN (' E002540 ')) THEN T3."Menge (Stunde)"
|
|
|
+ ELSE 0
|
|
|
+END < 0 AND T3."Nr_" NOT like ' HU - K % ' THEN(convert(float(53) ,T3."Vorgabezeit") / T3."Menge pro Stunde") * -1
|
|
|
+ELSE T3."Vorgabezeit"
|
|
|
+END ,
|
|
|
+T3."AW Mont_ 2"
|
|
|
+,
|
|
|
+T3."AW Mont_ 1"
|
|
|
+,
|
|
|
+T3."Vorgabezeitart"
|
|
|
+,
|
|
|
+T3."Vorgabezeit"
|
|
|
+,
|
|
|
+T3."Menge (Stunde)"
|
|
|
+,
|
|
|
+T3."Menge pro Stunde"
|
|
|
+, CASE WHEN T3."Produktbuchungsgruppe" NOT IN (' W_KARO ',' W_MECH ',' W_LACK ',' W_KARO_AZK ',' W_LACK_AZE ') AND T3."Produktbuchungsgruppe" NOT like ' T \ _ % ' escape ' \ ' or T3."Nr_" = ' E002540 ' THEN T3."Einstandsbetrag"
|
|
|
+ ELSE 0
|
|
|
+END , CASE WHEN T3."Produktbuchungsgruppe" like ' T \ _ % ' escape ' \ ' THEN T3."Einstandsbetrag"
|
|
|
+ELSE 0
|
|
|
+END , CASE WHEN case WHEN(T3."Geschäftsbuchungsgruppe"IN (' C_INTERN ',' INTERN ',' P_INTERN ')) THEN ' Intern '
|
|
|
+WHEN(T3."Geschäftsbuchungsgruppe"IN (' GAR_NST ',' GAR_STB ')) THEN ' GWL '
|
|
|
+ELSE ' Extern '
|
|
|
+END = ' Intern ' THEN T3."Verrechnungsbetrag"
|
|
|
+ELSE CASE WHEN T3."Offen" = 0 THEN T3."Verkaufsbetrag" * -1
|
|
|
+ELSE T3."Verkaufsbetrag"
|
|
|
+END
|
|
|
+END , CASE WHEN T3."Kostenstellencode" like ' 1 % ' THEN ' 1 '
|
|
|
+WHEN T3."Kostenstellencode" like ' 2 % ' THEN ' 2 '
|
|
|
+WHEN T3."Kostenstellencode" IN (' 30 ',' 31 ',' 60 ') THEN ' 6 '
|
|
|
+WHEN T3."Kostenstellencode" IN (' 40 ',' 62 ') THEN ' 3 '
|
|
|
+WHEN T3."Kostenstellencode" = ' 41 ' THEN ' 4 '
|
|
|
+WHEN T3."Kostenstellencode" = ' 42 ' THEN ' 5 '
|
|
|
+WHEN T3."Kostenstellencode" like ' 7 % ' THEN ' 7 '
|
|
|
+WHEN T3."Kostenstellencode" like ' 9 % ' THEN ' 0 '
|
|
|
+ELSE NULL
|
|
|
+END ,
|
|
|
+T3."Fahrgestellnummer" + ' - ' + T7."Modell"
|
|
|
+,
|
|
|
+T7."Modell"
|
|
|
+,
|
|
|
+T6."Name"
|
|
|
+,
|
|
|
+T6."Nr_"
|
|
|
+, CASE WHEN T3."Herkunftsnr_" like ' % INT % ' or CASE WHEN T1."Verk_ an Deb_-Nr_" is null THEN T2."Verk_ an Deb_-Nr_"
|
|
|
+ELSE T1."Verk_ an Deb_-Nr_"
|
|
|
+END like ' % INT % ' or CASE WHEN T1."Rech_ an Deb_-Nr_" is null THEN T2."Rech_ an Deb_-Nr_"
|
|
|
+ ELSE T1."Rech_ an Deb_-Nr_"
|
|
|
+END like ' % INT % ' THEN ' Intern '
|
|
|
+WHEN T3."Belegtyp" = 2 AND(T3."Herkunftsnr_" NOT like ' % INT % ' orCASE WHEN T1."Verk_ an Deb_-Nr_" is null THEN T2."Verk_ an Deb_-Nr_"
|
|
|
+ ELSE T1."Verk_ an Deb_-Nr_"
|
|
|
+END NOT like ' % INT % ' or CASE WHEN T1."Rech_ an Deb_-Nr_" is null THEN T2."Rech_ an Deb_-Nr_"
|
|
|
+ ELSE T1."Rech_ an Deb_-Nr_"
|
|
|
+ END NOT like ' % INT % ') THEN ' Extern '
|
|
|
+WHEN T3."Belegtyp" = 3 AND(T3."Herkunftsnr_" NOT like ' % INT % ' orCASE WHEN T1."Verk_ an Deb_-Nr_" is null THEN T2."Verk_ an Deb_-Nr_"
|
|
|
+ ELSE T1."Verk_ an Deb_-Nr_"
|
|
|
+END NOT like ' % INT % ' or CASE WHEN T1."Rech_ an Deb_-Nr_" is null THEN T2."Rech_ an Deb_-Nr_"
|
|
|
+ ELSE T1."Rech_ an Deb_-Nr_"
|
|
|
+ END NOT like ' % INT % ') THEN ' GWL '
|
|
|
+ ELSE NULL
|
|
|
+END , CASE WHEN T1."Rech_ an Deb_-Nr_" is null THEN T2."Rech_ an Deb_-Nr_"
|
|
|
+ELSE T1."Rech_ an Deb_-Nr_"
|
|
|
+END , CASE WHEN T3."Offen" = 0 THEN T3."Verkaufsbetrag" * -1
|
|
|
+ELSE T3."Verkaufsbetrag"
|
|
|
+END ,
|
|
|
+T3."Einstandsbetrag"
|
|
|
+,
|
|
|
+T3."Menge"
|
|
|
+,
|
|
|
+T5."Nachname"
|
|
|
+,
|
|
|
+T5."Vorname"
|
|
|
+, CASE WHEN ' 1 ' = ' 2 ' THEN ' 20 '
|
|
|
+ELSE CASE WHEN T1."Filialcode" is null THEN T2."Filialcode"
|
|
|
+ELSE T1."Filialcode"
|
|
|
+END
|
|
|
+END ,
|
|
|
+T4."Bezeichnung"
|
|
|
+,
|
|
|
+T4."Code"
|
|
|
+,
|
|
|
+T3."Monteur Nr_ 2"
|
|
|
+,
|
|
|
+T3."Monteur Nr_ 1"
|
|
|
+,
|
|
|
+T3."Serviceberaternr_"
|
|
|
+,
|
|
|
+T3."Auftragszeilennr_"
|
|
|
+,
|
|
|
+T3."Herkunftsnr_"
|
|
|
+,
|
|
|
+T3."Fahrzeugartencode"
|
|
|
+,
|
|
|
+T3."Artikelgruppencode"
|
|
|
+,
|
|
|
+T3."Fahrgestellnummer"
|
|
|
+,
|
|
|
+T3."Nummernserie"
|
|
|
+,
|
|
|
+T3."Belegdatum"
|
|
|
+,
|
|
|
+T3."Produktbuchungsgruppe"
|
|
|
+,
|
|
|
+T3."Herkunftscode"
|
|
|
+,
|
|
|
+T3."Benutzer ID"
|
|
|
+,
|
|
|
+T3."Kostenstellencode"
|
|
|
+,
|
|
|
+T3."Werkstattbuchungsgruppe"
|
|
|
+,
|
|
|
+T3."Verkaufsbetrag"
|
|
|
+,
|
|
|
+T3."VK-Preis"
|
|
|
+,
|
|
|
+T3."Einstandspreis"
|
|
|
+,
|
|
|
+T3."EK-Preis"
|
|
|
+,
|
|
|
+T3."Beschreibung"
|
|
|
+,
|
|
|
+T3."Nr_"
|
|
|
+,
|
|
|
+T3."Art"
|
|
|
+,
|
|
|
+T3."Belegnr_"
|
|
|
+, CASE WHEN T1."Verk_ an Deb_-Nr_" is null THEN T2."Verk_ an Deb_-Nr_"
|
|
|
+ELSE T1."Verk_ an Deb_-Nr_"
|
|
|
+END , CASE WHEN T1."Nr_" is null THEN T2."Nr_"
|
|
|
+ELSE T1."Nr_"
|
|
|
+END , CASE WHEN T1."Belegart" is null THEN T2."Belegart"
|
|
|
+ELSE T1."Belegart"
|
|
|
+END ,
|
|
|
+T1."Interne Belegnr_"
|
|
|
+,
|
|
|
+T1."Interner Auftrag"
|
|
|
+,
|
|
|
+T1."Filialcode"
|
|
|
+,
|
|
|
+T1."Buchungsdatum"
|
|
|
+,
|
|
|
+T1."Auftragsdatum"
|
|
|
+,
|
|
|
+T1."Verk_ an Deb_-Nr_"
|
|
|
+,
|
|
|
+T1."Nr_"
|
|
|
+,
|
|
|
+T1."Belegart"
|
|
|
+FROM((((((((("CARLO"."import"."Werkstattposten" T3 FULL OUTER JOIN
|
|
|
+"CARLO"."import"."Archiv_Werkstattkopf" T1 ON T3."Auftragsnr_" = T1."Nr_"
|
|
|
+AND T3."Client_DB" = T1."Client_DB") FULL OUTER JOIN
|
|
|
+"CARLO"."import"."Werkstattkopf" T2 ON T2."Nr_" = T3."Auftragsnr_"
|
|
|
+AND T2."Client_DB" = T3."Client_DB") LEFT OUTER JOIN
|
|
|
+"CARLO"."import"."Filialbezeichnung" T4 ON T3."Filialcode" = T4."Code"
|
|
|
+AND T3."Client_DB" = T4."Client_DB") LEFT OUTER JOIN
|
|
|
+"CARLO"."import"."Employee" T5 ON T3."Serviceberaternr_" = T5."Nr_"
|
|
|
+AND T3."Client_DB" = T5."Client_DB") LEFT OUTER JOIN
|
|
|
+"CARLO"."import"."Debitor" T6 ON T3."Herkunftsnr_" = T6."Nr_"
|
|
|
+AND T3."Client_DB" = T6."Client_DB") LEFT OUTER JOIN
|
|
|
+"CARLO"."import"."Fahrzeug" T7 ON T3."Fahrgestellnummer" = T7."Fahrgestellnummer"
|
|
|
+AND T3."Client_DB" = T7."Client_DB") LEFT OUTER JOIN
|
|
|
+"CARLO"."import"."Artikel" T8 ON T3."Nr_" = T8."Nr_"
|
|
|
+AND T3."Client_DB" = T8."Client_DB") LEFT OUTER JOIN
|
|
|
+"CARLO"."import"."Kostenstelle" T9 ON T3."Kostenstellencode" = T9."Code"
|
|
|
+AND T3."Client_DB" = T9."Client_DB") FULL OUTER JOIN
|
|
|
+"CARLO"."import"."Verkaufsrechnungskopf" T11 ON T11."Nr_" = T3."Belegnr_"
|
|
|
+AND T11."Client_DB" = T3."Client_DB") LEFT OUTER JOIN
|
|
|
+"CARLO"."import"."Debitor" T10 ON T11."Verk_ an Deb_-Nr_" = T10."Nr_" AND T11."Client_DB" = T10."Client_DB"
|
|
|
+WHERE CASE WHEN(T3."Geschäftsbuchungsgruppe"IN (' C_INTERN ',' INTERN ',' P_INTERN ')) THEN ' Intern '
|
|
|
+WHEN(T3."Geschäftsbuchungsgruppe"IN (' GAR_NST ',' GAR_STB ')) THEN ' GWL '
|
|
|
+else ' Extern '
|
|
|
+end = ' Intern ' AND(T3."Art" <> 2
|
|
|
+AND T3."Belegnr_" NOT like ' G % '
|
|
|
+AND T3."Abgeschlossen" = 1
|
|
|
+AND T3."Nummernserie" <> ''
|
|
|
+AND T3."Offen" = 0
|
|
|
+AND(T3."Belegnr_" like ' WVRG % ' or T3."Belegnr_" like ' WSGG % ')
|
|
|
+AND T3."Nummernserie" <> ' WSLIEFG ' or T3."Art" <> 2
|
|
|
+AND T3."Belegnr_" NOT like ' G % '
|
|
|
+AND T3."Abgeschlossen" = 1
|
|
|
+AND T3."Nummernserie" <> ''
|
|
|
+AND T3."Offen" = 1
|
|
|
+AND(T3."Belegnr_" like ' WVLG % ' or T3."Belegnr_" like ' WVGL % ') or T3."Art" <> 2
|
|
|
+AND T3."Belegnr_" NOT like ' G % '
|
|
|
+AND T3."Abgeschlossen" = 1
|
|
|
+AND T3."Offen" = 1
|
|
|
+AND T3."Belegnr_" like ' WVAN % ') AND CASE WHEN T1."Buchungsdatum" is null THEN T2."Buchungsdatum"
|
|
|
+else T1."Buchungsdatum"
|
|
|
+end >= {ts ' 2018 -01 -01 00 :00 :00.000 '}
|
|
|
+ORDER BY 1 asc
|