select "Accounting Date" as "Accounting Date",
	   "Document Type" as "Document Type",
	   "Document Number" as "Document Number",
	   "Position In Document" as "Position In Document",
	   "Nominal Account Number" as "Nominal Account Number",
	   "Customer Number" as "Customer Number",
	   "Is Balanced" as "Is Balanced",
	   "Clearing Number" as "Clearing Number",
	   "Document Date" as "Document Date",
	   "Posted Value" as "Posted Value",
	   "Debit Or Credit" as "Debit Or Credit",
	   "Posted Count" as "Posted Count",
	   "Branch Number" as "Branch Number",
	   "Customer Contra Account" as "Customer Contra Account",
	   "Nominal Contra Account" as "Nominal Contra Account",
	   "Contra Account Text" as "Contra Account Text",
	   "Account Form Page Number" as "Account Form Page Number",
	   "Account Form Page Line" as "Account Form Page Line",
	   "Serial Number Each Month" as "Serial Number Each Month",
	   "Employee Number" as "Employee Number",
	   "Invoice Date" as "Invoice Date",
	   "Invoice Number" as "Invoice Number",
	   "Dunning Level" as "Dunning Level",
	   "Last Dunning Date" as "Last Dunning Date",
	   "Journal Page" as "Journal Page",
	   "Journal Line" as "Journal Line",
	   "Cash Discount" as "Cash Discount",
	   "Term Of Payment" as "Term Of Payment",
	   "Posting Text" as "Posting Text",
	   "Vehicle Reference" as "Vehicle Reference",
	   "Vat Id Number" as "Vat Id Number",
	   "Account Statement Number" as "Account Statement Number",
	   "Account Statement Page" as "Account Statement Page",
	   "Vat Key" as "Vat Key",
	   "Days For Cash Discount" as "Days For Cash Discount",
	   "Day Of Actual Accounting" as "Day Of Actual Accounting",
	   "Skr51 Branch" as "Skr51 Branch",
	   "Skr51 Make" as "Skr51 Make",
	   "Skr51 Cost Center" as "Skr51 Cost Center",
	   "Skr51 Sales Channel" as "Skr51 Sales Channel",
	   "Skr51 Cost Unit" as "Skr51 Cost Unit",
	   "Previously Used Account No" as "Previously Used Account No",
	   "Free Form Accounting Text" as "Free Form Accounting Text",
	   "Free Form Document Text" as "Free Form Document Text",
	   "Rechtseinheit" as "Rechtseinheit",
	   "Betrieb" as "Betrieb",
	   "Bookkeep Date" as "Bookkeep Date",
	   "Text" as "Text",
	   "Mandant" as "Mandant",
	   "Betrag" as "Betrag",
	   "Menge" as "Menge",
	   "Acct Nr" as "Acct Nr",
	   "Customer Number_suctomer_supplier" as "Customer Number_suctomer_supplier",
	   "Is Supplier" as "Is Supplier",
	   "First Name" as "First Name",
	   "Family Name" as "Family Name",
	   "Document Type In Journal" as "Document Type In Journal",
	   "Document Type Description" as "Document Type Description",
	   SUM("Betrag") OVER (partition by "Customer Number_suctomer_supplier") as "Debitorsaldo",
	   "Invoice Type_Invoices" as "Invoice Type_Invoices",
	   "Invoice Number_Invoices" as "Invoice Number_Invoices",
	   "Subsidiary_Invoices" as "Subsidiary_Invoices",
	   "Invoice Date_Invoices" as "Invoice Date_Invoices",
	   "Hauptbetrieb" as "Hauptbetrieb",
	   "Standort_ori" as "Standort_ori",
	   "Sel Name" as "Sel Name",
	   "OP-Saldo_" as "OP-Saldo_",
	   "Kostenstelle" as "Kostenstelle",
	   "Tage" as "Tage",
	   "Staffel" as "Staffel",
	   "Kunde" as "Kunde",
	   "Beleg" as "Beleg",
	   "Employee Number_Employees_journal_accountings" as "Employee Number_Employees_journal_accountings",
	   "Name_Employees_journal_accountings" as "Name_Employees_journal_accountings",
	   "Anzahl_Stellen_Invoice_Number" as "Anzahl_Stellen_Invoice_Number",
	   "Forderungsart_aus_erste_Stelle_Inv_Number" as "Forderungsart_aus_erste_Stelle_Inv_Number",
	   "Forderungsart" as "Forderungsart",
	   "Standort_aus_2_Stelle_Invoice_Number" as "Standort_aus_2_Stelle_Invoice_Number",
	   "Standort" as "Standort"
from 
(select "Accounting Date",
	   "Document Type",
	   "Document Number",
	   "Position In Document",
	   "Nominal Account Number",
	   "Customer Number",
	   "Is Balanced",
	   "Clearing Number",
	   "Document Date",
	   "Posted Value",
	   "Debit Or Credit",
	   "Posted Count",
	   "Branch Number",
	   "Customer Contra Account",
	   "Nominal Contra Account",
	   "Contra Account Text",
	   "Account Form Page Number",
	   "Account Form Page Line",
	   "Serial Number Each Month",
	   "Employee Number",
	   "Invoice Date",
	   "Invoice Number",
	   "Dunning Level",
	   "Last Dunning Date",
	   "Journal Page",
	   "Journal Line",
	   "Cash Discount",
	   "Term Of Payment",
	   "Posting Text",
	   "Vehicle Reference",
	   "Vat Id Number",
	   "Account Statement Number",
	   "Account Statement Page",
	   "Vat Key",
	   "Days For Cash Discount",
	   "Day Of Actual Accounting",
	   "Skr51 Branch",
	   "Skr51 Make",
	   "Skr51 Cost Center",
	   "Skr51 Sales Channel",
	   "Skr51 Cost Unit",
	   "Previously Used Account No",
	   "Free Form Accounting Text",
	   "Free Form Document Text",
	   '1' as "Rechtseinheit",
	   "Betrieb",
	   "Accounting Date" as "Bookkeep Date",
	   "Text",
	   '1' as "Mandant",
	   "Betrag",
	   "Menge",
	   "Nominal Account Number" as "Acct Nr",
	   "Customer Number_suctomer_supplier",
	   "Is Supplier",
	   "First Name",
	   "Family Name",
	   "Document Type In Journal",
	   "Document Type Description",
	   "Invoice Type_Invoices",
	   "Invoice Number_Invoices",
	   "Subsidiary_Invoices",
	   "Invoice Date_Invoices",
	   "Hauptbetrieb",
	   "Standort_ori",
	   "Sel Name",
	   "Betrag" as "OP-Saldo_",
	   "Kostenstelle",
	   "Tage",
	   "Staffel",
	   "Kunde",
	   "Beleg",
	   "Employee Number_Employees_journal_accountings",
	   "Name_Employees_journal_accountings",
	   "Anzahl_Stellen_Invoice_Number",
	   "Forderungsart_aus_erste_Stelle_Inv_Number",
	   "Forderungsart",
	   "Standort_aus_2_Stelle_Invoice_Number",
	   "Betrieb" as "Standort",
	   SUM("Betrag") OVER (partition by "Customer Number_suctomer_supplier") as c80
from 
(select T3."customer_number" as "Customer Number_suctomer_supplier",
	   ('0' + (((T1."branch_number")))) as "Betrieb",
	   CASE WHEN ((((len((CASE WHEN ((T1."invoice_number" IS NULL) or (T1."invoice_number" = ' ')) THEN (' - ') ELSE (T1."invoice_number") END)))) = 7) and ((substring((CASE WHEN ((T1."invoice_number" IS NULL) or (T1."invoice_number" = ' ')) THEN (' - ') ELSE (T1."invoice_number") END), 2, 1)) BETWEEN '1' AND '4')) THEN ('0' + (substring((CASE WHEN ((T1."invoice_number" IS NULL) or (T1."invoice_number" = ' ')) THEN (' - ') ELSE (T1."invoice_number") END), 2, 1))) ELSE null END as "Standort_aus_2_Stelle_Invoice_Number",
	   CASE WHEN ((CASE WHEN (T5."invoice_type" IN (2,4,6,3)) THEN ('3') WHEN (T5."invoice_type" IN (5)) THEN ('6') WHEN (T5."invoice_type" IN (7)) THEN ('1') WHEN (T5."invoice_type" IN (8)) THEN ('2') WHEN (T4."document_type_in_journal" = 'R') THEN ('7') ELSE null END) = '1') THEN ('Neuwagen') WHEN ((CASE WHEN (T5."invoice_type" IN (2,4,6,3)) THEN ('3') WHEN (T5."invoice_type" IN (5)) THEN ('6') WHEN (T5."invoice_type" IN (7)) THEN ('1') WHEN (T5."invoice_type" IN (8)) THEN ('2') WHEN (T4."document_type_in_journal" = 'R') THEN ('7') ELSE null END) = '2') THEN ('Gebrauchtwagen') WHEN ((CASE WHEN (T5."invoice_type" IN (2,4,6,3)) THEN ('3') WHEN (T5."invoice_type" IN (5)) THEN ('6') WHEN (T5."invoice_type" IN (7)) THEN ('1') WHEN (T5."invoice_type" IN (8)) THEN ('2') WHEN (T4."document_type_in_journal" = 'R') THEN ('7') ELSE null END) = '3') THEN ('Service') WHEN ((CASE WHEN (T5."invoice_type" IN (2,4,6,3)) THEN ('3') WHEN (T5."invoice_type" IN (5)) THEN ('6') WHEN (T5."invoice_type" IN (7)) THEN ('1') WHEN (T5."invoice_type" IN (8)) THEN ('2') WHEN (T4."document_type_in_journal" = 'R') THEN ('7') ELSE null END) = '6') THEN ('Teile') ELSE ('nicht zuzuordnen') END as "Forderungsart",
	   CASE WHEN ((((len((CASE WHEN ((T1."invoice_number" IS NULL) or (T1."invoice_number" = ' ')) THEN (' - ') ELSE (T1."invoice_number") END)))) = 7) and ((substring((CASE WHEN ((T1."invoice_number" IS NULL) or (T1."invoice_number" = ' ')) THEN (' - ') ELSE (T1."invoice_number") END), 1, 1)) IN ('2','3','4'))) THEN ('Service') WHEN ((((len((CASE WHEN ((T1."invoice_number" IS NULL) or (T1."invoice_number" = ' ')) THEN (' - ') ELSE (T1."invoice_number") END)))) = 7) and ((substring((CASE WHEN ((T1."invoice_number" IS NULL) or (T1."invoice_number" = ' ')) THEN (' - ') ELSE (T1."invoice_number") END), 1, 1)) IN ('5'))) THEN ('Teile') WHEN ((((len((CASE WHEN ((T1."invoice_number" IS NULL) or (T1."invoice_number" = ' ')) THEN (' - ') ELSE (T1."invoice_number") END)))) = 7) and ((substring((CASE WHEN ((T1."invoice_number" IS NULL) or (T1."invoice_number" = ' ')) THEN (' - ') ELSE (T1."invoice_number") END), 1, 1)) IN ('6'))) THEN ('Garantie') WHEN ((((len((CASE WHEN ((T1."invoice_number" IS NULL) or (T1."invoice_number" = ' ')) THEN (' - ') ELSE (T1."invoice_number") END)))) = 7) and ((substring((CASE WHEN ((T1."invoice_number" IS NULL) or (T1."invoice_number" = ' ')) THEN (' - ') ELSE (T1."invoice_number") END), 1, 1)) IN ('7'))) THEN ('Neuwagen') WHEN ((((len((CASE WHEN ((T1."invoice_number" IS NULL) or (T1."invoice_number" = ' ')) THEN (' - ') ELSE (T1."invoice_number") END)))) = 7) and ((substring((CASE WHEN ((T1."invoice_number" IS NULL) or (T1."invoice_number" = ' ')) THEN (' - ') ELSE (T1."invoice_number") END), 1, 1)) IN ('8'))) THEN ('Gebrauchtwagen') WHEN (T1."document_type" = 'R') THEN ('Rent') ELSE ('nicht zuzuordnen') END as "Forderungsart_aus_erste_Stelle_Inv_Number",
	   (len((CASE WHEN ((T1."invoice_number" IS NULL) or (T1."invoice_number" = ' ')) THEN (' - ') ELSE (T1."invoice_number") END))) as "Anzahl_Stellen_Invoice_Number",
	   T2."name" as "Name_Employees_journal_accountings",
	   T2."employee_number" as "Employee Number_Employees_journal_accountings",
	   ((CASE WHEN ((T1."posting_text" IS NULL) or (T1."posting_text" = ' ')) THEN (' - ') ELSE (T1."posting_text") END) + '/' + (CASE WHEN ((T1."vehicle_reference" IS NULL) or (T1."vehicle_reference" = ' ')) THEN (' - ') ELSE (T1."vehicle_reference") END)) as "Beleg",
	   CASE WHEN (T3."first_name" IS NOT NULL) THEN ((left((((T3."customer_number"))),7)) + ' - ' + T3."first_name" + ' ' + T3."family_name") ELSE ((left((((T3."customer_number"))),7)) + ' ' + T3."family_name") END as "Kunde",
	   CASE WHEN (((-1 * datediff(day, (getdate()), (convert(datetime, T1."accounting_date"))))) BETWEEN 0 AND 14) THEN ('< 2 Wochen') WHEN (((-1 * datediff(day, (getdate()), (convert(datetime, T1."accounting_date"))))) BETWEEN 15 AND 28) THEN ('2 - 4 Wochen') WHEN (((-1 * datediff(day, (getdate()), (convert(datetime, T1."accounting_date"))))) BETWEEN 29 AND 42) THEN ('4 - 6 Wochen') WHEN (((-1 * datediff(day, (getdate()), (convert(datetime, T1."accounting_date"))))) BETWEEN 43 AND 84) THEN ('6 - 12 Wochen') WHEN (((-1 * datediff(day, (getdate()), (convert(datetime, T1."accounting_date"))))) > 84) THEN ('> 12 Wochen') ELSE null END as "Staffel",
	   (-1 * datediff(day, (getdate()), (convert(datetime, T1."accounting_date")))) as "Tage",
	   CASE WHEN (T5."invoice_type" IN (2,4,6,3)) THEN ('3') WHEN (T5."invoice_type" IN (5)) THEN ('6') WHEN (T5."invoice_type" IN (7)) THEN ('1') WHEN (T5."invoice_type" IN (8)) THEN ('2') WHEN (T4."document_type_in_journal" = 'R') THEN ('7') ELSE null END as "Kostenstelle",
	   (CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_value" / 100 * -1) ELSE (T1."posted_value" / 100) END) as "Betrag",
	   (left((((T2."employee_number"))),4)) + ' - ' + T2."name" as "Sel Name",
	   CASE WHEN (T5."subsidiary" IS NOT NULL) THEN ('0' + (left((((T5."subsidiary"))),1))) ELSE ('nicht zuzuordnen') END as "Standort_ori",
	   CASE WHEN ((('0' + (((T1."branch_number"))))) IN ('015                                                                                                                                                                                                                                                            ')) THEN ('15') ELSE ('1') END as "Hauptbetrieb",
	   T5."invoice_date" as "Invoice Date_Invoices",
	   T5."subsidiary" as "Subsidiary_Invoices",
	   T5."invoice_number" as "Invoice Number_Invoices",
	   T5."invoice_type" as "Invoice Type_Invoices",
	   T4."document_type_description" as "Document Type Description",
	   T4."document_type_in_journal" as "Document Type In Journal",
	   T3."family_name" as "Family Name",
	   T3."first_name" as "First Name",
	   T3."is_supplier" as "Is Supplier",
	   T1."nominal_account_number" as "Nominal Account Number",
	   CASE WHEN (T1."debit_or_credit" = 'H') THEN (T1."posted_count" / 100 * -1) ELSE (T1."posted_count" / 100) END as "Menge",
	   CASE WHEN ((CASE WHEN ((T1."posting_text" IS NULL) or (T1."posting_text" = ' ')) THEN (' - ') ELSE (T1."posting_text") END) IS NOT NULL) THEN ((rtrim((convert(varchar(50), ((T1."document_number")))))) + ' - ' + (CASE WHEN ((T1."posting_text" IS NULL) or (T1."posting_text" = ' ')) THEN (' - ') ELSE (T1."posting_text") END) + '/' + (CASE WHEN ((T1."vehicle_reference" IS NULL) or (T1."vehicle_reference" = ' ')) THEN (' - ') ELSE (T1."vehicle_reference") END) + ' - ' + ((left((((T2."employee_number"))))) + ' - ' + T2."name") + ' - ' + (convert(varchar(50), year(T1."document_date")) + '-' + convert(varchar(50), month(T1."document_date")) + '-' + convert(varchar(50), day(T1."document_date")))) ELSE ((rtrim((convert(varchar(50), ((T1."document_number")))))) + ' - ' + (CASE WHEN ((T1."vehicle_reference" IS NULL) or (T1."vehicle_reference" = ' ')) THEN (' - ') ELSE (T1."vehicle_reference") END) + ' - ' + ((left((((T2."employee_number"))))) + ' - ' + T2."name") + ' - ' + (convert(varchar(50), year(T1."document_date")) + '-' + convert(varchar(50), month(T1."document_date")) + '-' + convert(varchar(50), day(T1."document_date")))) END as "Text",
	   T1."accounting_date" as "Accounting Date",
	   CASE WHEN ((((((CASE WHEN ((CASE WHEN ((T1."posting_text" IS NULL) or (T1."posting_text" = ' ')) THEN (' - ') ELSE (T1."posting_text") END) IS NOT NULL) THEN ((rtrim((convert(varchar(50), ((T1."document_number")))))) + ' - ' + (CASE WHEN ((T1."posting_text" IS NULL) or (T1."posting_text" = ' ')) THEN (' - ') ELSE (T1."posting_text") END) + '/' + (CASE WHEN ((T1."vehicle_reference" IS NULL) or (T1."vehicle_reference" = ' ')) THEN (' - ') ELSE (T1."vehicle_reference") END) + ' - ' + ((left((((T2."employee_number"))))) + ' - ' + T2."name") + ' - ' + (convert(varchar(50), year(T1."document_date")) + '-' + convert(varchar(50), month(T1."document_date")) + '-' + convert(varchar(50), day(T1."document_date")))) ELSE ((rtrim((convert(varchar(50), ((T1."document_number")))))) + ' - ' + (CASE WHEN ((T1."vehicle_reference" IS NULL) or (T1."vehicle_reference" = ' ')) THEN (' - ') ELSE (T1."vehicle_reference") END) + ' - ' + ((left((((T2."employee_number"))))) + ' - ' + T2."name") + ' - ' + (convert(varchar(50), year(T1."document_date")) + '-' + convert(varchar(50), month(T1."document_date")) + '-' + convert(varchar(50), day(T1."document_date")))) END) LIKE '%RG-BONUS%') or ((CASE WHEN ((CASE WHEN ((T1."posting_text" IS NULL) or (T1."posting_text" = ' ')) THEN (' - ') ELSE (T1."posting_text") END) IS NOT NULL) THEN ((rtrim((convert(varchar(50), ((T1."document_number")))))) + ' - ' + (CASE WHEN ((T1."posting_text" IS NULL) or (T1."posting_text" = ' ')) THEN (' - ') ELSE (T1."posting_text") END) + '/' + (CASE WHEN ((T1."vehicle_reference" IS NULL) or (T1."vehicle_reference" = ' ')) THEN (' - ') ELSE (T1."vehicle_reference") END) + ' - ' + ((left((((T2."employee_number"))))) + ' - ' + T2."name") + ' - ' + (convert(varchar(50), year(T1."document_date")) + '-' + convert(varchar(50), month(T1."document_date")) + '-' + convert(varchar(50), day(T1."document_date")))) ELSE ((rtrim((convert(varchar(50), ((T1."document_number")))))) + ' - ' + (CASE WHEN ((T1."vehicle_reference" IS NULL) or (T1."vehicle_reference" = ' ')) THEN (' - ') ELSE (T1."vehicle_reference") END) + ' - ' + ((left((((T2."employee_number"))))) + ' - ' + T2."name") + ' - ' + (convert(varchar(50), year(T1."document_date")) + '-' + convert(varchar(50), month(T1."document_date")) + '-' + convert(varchar(50), day(T1."document_date")))) END) LIKE '%GEBURTSTAGS%')) or ((CASE WHEN ((CASE WHEN ((T1."posting_text" IS NULL) or (T1."posting_text" = ' ')) THEN (' - ') ELSE (T1."posting_text") END) IS NOT NULL) THEN ((rtrim((convert(varchar(50), ((T1."document_number")))))) + ' - ' + (CASE WHEN ((T1."posting_text" IS NULL) or (T1."posting_text" = ' ')) THEN (' - ') ELSE (T1."posting_text") END) + '/' + (CASE WHEN ((T1."vehicle_reference" IS NULL) or (T1."vehicle_reference" = ' ')) THEN (' - ') ELSE (T1."vehicle_reference") END) + ' - ' + ((left((((T2."employee_number"))))) + ' - ' + T2."name") + ' - ' + (convert(varchar(50), year(T1."document_date")) + '-' + convert(varchar(50), month(T1."document_date")) + '-' + convert(varchar(50), day(T1."document_date")))) ELSE ((rtrim((convert(varchar(50), ((T1."document_number")))))) + ' - ' + (CASE WHEN ((T1."vehicle_reference" IS NULL) or (T1."vehicle_reference" = ' ')) THEN (' - ') ELSE (T1."vehicle_reference") END) + ' - ' + ((left((((T2."employee_number"))))) + ' - ' + T2."name") + ' - ' + (convert(varchar(50), year(T1."document_date")) + '-' + convert(varchar(50), month(T1."document_date")) + '-' + convert(varchar(50), day(T1."document_date")))) END) LIKE '%STARTGUTHABEN%')) or ((CASE WHEN ((CASE WHEN ((T1."posting_text" IS NULL) or (T1."posting_text" = ' ')) THEN (' - ') ELSE (T1."posting_text") END) IS NOT NULL) THEN ((rtrim((convert(varchar(50), ((T1."document_number")))))) + ' - ' + (CASE WHEN ((T1."posting_text" IS NULL) or (T1."posting_text" = ' ')) THEN (' - ') ELSE (T1."posting_text") END) + '/' + (CASE WHEN ((T1."vehicle_reference" IS NULL) or (T1."vehicle_reference" = ' ')) THEN (' - ') ELSE (T1."vehicle_reference") END) + ' - ' + ((left((((T2."employee_number"))))) + ' - ' + T2."name") + ' - ' + (convert(varchar(50), year(T1."document_date")) + '-' + convert(varchar(50), month(T1."document_date")) + '-' + convert(varchar(50), day(T1."document_date")))) ELSE ((rtrim((convert(varchar(50), ((T1."document_number")))))) + ' - ' + (CASE WHEN ((T1."vehicle_reference" IS NULL) or (T1."vehicle_reference" = ' ')) THEN (' - ') ELSE (T1."vehicle_reference") END) + ' - ' + ((left((((T2."employee_number"))))) + ' - ' + T2."name") + ' - ' + (convert(varchar(50), year(T1."document_date")) + '-' + convert(varchar(50), month(T1."document_date")) + '-' + convert(varchar(50), day(T1."document_date")))) END) LIKE '%BONUS F%')) or ((CASE WHEN ((CASE WHEN ((T1."posting_text" IS NULL) or (T1."posting_text" = ' ')) THEN (' - ') ELSE (T1."posting_text") END) IS NOT NULL) THEN ((rtrim((convert(varchar(50), ((T1."document_number")))))) + ' - ' + (CASE WHEN ((T1."posting_text" IS NULL) or (T1."posting_text" = ' ')) THEN (' - ') ELSE (T1."posting_text") END) + '/' + (CASE WHEN ((T1."vehicle_reference" IS NULL) or (T1."vehicle_reference" = ' ')) THEN (' - ') ELSE (T1."vehicle_reference") END) + ' - ' + ((left((((T2."employee_number"))))) + ' - ' + T2."name") + ' - ' + (convert(varchar(50), year(T1."document_date")) + '-' + convert(varchar(50), month(T1."document_date")) + '-' + convert(varchar(50), day(T1."document_date")))) ELSE ((rtrim((convert(varchar(50), ((T1."document_number")))))) + ' - ' + (CASE WHEN ((T1."vehicle_reference" IS NULL) or (T1."vehicle_reference" = ' ')) THEN (' - ') ELSE (T1."vehicle_reference") END) + ' - ' + ((left((((T2."employee_number"))))) + ' - ' + T2."name") + ' - ' + (convert(varchar(50), year(T1."document_date")) + '-' + convert(varchar(50), month(T1."document_date")) + '-' + convert(varchar(50), day(T1."document_date")))) END) LIKE '%RG-ABZUG%')) THEN ('Bonus/Startguthaben') ELSE ('ohne Bonus/Startguthaben') END as "Free Form Document Text",
	   T1."free_form_accounting_text" as "Free Form Accounting Text",
	   T1."previously_used_account_no" as "Previously Used Account No",
	   T1."skr51_cost_unit" as "Skr51 Cost Unit",
	   T1."skr51_sales_channel" as "Skr51 Sales Channel",
	   T1."skr51_cost_center" as "Skr51 Cost Center",
	   T1."skr51_make" as "Skr51 Make",
	   T1."skr51_branch" as "Skr51 Branch",
	   T1."day_of_actual_accounting" as "Day Of Actual Accounting",
	   (convert(varchar(50), year(T1."accounting_date")) + '-' + convert(varchar(50), month(T1."accounting_date")) + '-' + convert(varchar(50), day(T1."accounting_date"))) as "Days For Cash Discount",
	   T1."vat_key" as "Vat Key",
	   T1."account_statement_page" as "Account Statement Page",
	   T1."account_statement_number" as "Account Statement Number",
	   T1."vat_id_number" as "Vat Id Number",
	   CASE WHEN ((T1."vehicle_reference" IS NULL) or (T1."vehicle_reference" = ' ')) THEN (' - ') ELSE (T1."vehicle_reference") END as "Vehicle Reference",
	   CASE WHEN ((T1."posting_text" IS NULL) or (T1."posting_text" = ' ')) THEN (' - ') ELSE (T1."posting_text") END as "Posting Text",
	   T1."term_of_payment" as "Term Of Payment",
	   T1."cash_discount" as "Cash Discount",
	   T1."journal_line" as "Journal Line",
	   T1."journal_page" as "Journal Page",
	   T1."last_dunning_date" as "Last Dunning Date",
	   T1."dunning_level" as "Dunning Level",
	   CASE WHEN ((T1."invoice_number" IS NULL) or (T1."invoice_number" = ' ')) THEN (' - ') ELSE (T1."invoice_number") END as "Invoice Number",
	   T1."invoice_date" as "Invoice Date",
	   T1."employee_number" as "Employee Number",
	   T1."serial_number_each_month" as "Serial Number Each Month",
	   T1."account_form_page_line" as "Account Form Page Line",
	   T1."account_form_page_number" as "Account Form Page Number",
	   T1."contra_account_text" as "Contra Account Text",
	   T1."nominal_contra_account" as "Nominal Contra Account",
	   T1."customer_contra_account" as "Customer Contra Account",
	   T1."branch_number" as "Branch Number",
	   T1."posted_count" as "Posted Count",
	   T1."debit_or_credit" as "Debit Or Credit",
	   T1."posted_value" as "Posted Value",
	   T1."document_date" as "Document Date",
	   T1."clearing_number" as "Clearing Number",
	   T1."is_balanced" as "Is Balanced",
	   T1."customer_number" as "Customer Number",
	   T1."position_in_document" as "Position In Document",
	   (T1."document_number") as "Document Number",
	   T1."document_type" as "Document Type"
from (((("journal_accountings" T1 left outer join "LOCOSOFT"."dbo"."employees" T2 on T1."employee_number" = T2."employee_number") left outer join "LOCOSOFT"."dbo"."customers_suppliers" T3 on T3."customer_number" = T1."customer_number") left outer join "document_types" T4 on T4."document_type_in_journal" = T1."document_type") left outer join "invoices" T5 on T5."invtype_invnr" = T1."invoice_number")
where (((((T1."nominal_account_number" IN (1400,1409,1451,1408,1525)) and (T1."clearing_number" = 0)) and (T1."customer_number" IS NOT NULL)) and (not T4."document_type_in_journal" IN ('A','E','U','V'))) and (T3."customer_number" IS NOT NULL))
) D2
) D1
where (c80 <> 0)
-- order by "Customer Number" asc,"Document Type In Journal" asc,"Nominal Account Number" asc