COGNOS QUERY STRUCTURE,1,1 DATABASE,GC_Navision DATASOURCENAME,C:\GlobalCube\System\NAVISION\IQD\belege\Teile_Fremdwerkstatt_FIBU_EW_Wertposten_Umsatz.imr TITLE,Teile_Fremdwerkstatt_FIBU_EW_Wertposten_Umsatz.imr BEGIN SQL select c1 as c1, c2 as c2, c3 as c3, c4 as c4, c5 as c5, c6 as c6, c7 as c7, c8 as c8, c9 as c9, c10 as c10, c11 as c11, c12 as c12, c13 as c13, c14 as c14, c15 as c15, c16 as c16, c17 as c17, c18 as c18, c19 as c19, c20 as c20, c21 as c21, c22 as c22, c23 as c23, c24 as c24, c25 as c25, c26 as c26, c27 as c27, c28 as c28, c29 as c29, c30 as c30, c31 as c31, c32 as c32, c33 as c33, c34 as c34, c35 as c35, c36 as c36, c37 as c37, c38 as c38, c39 as c39, c40 as c40, c41 as c41, c42 as c42, c43 as c43, c44 as c44, c45 as c45, c46 as c46, c47 as c47, c48 as c48, c49 as c49, c50 as c50, c51 as c51, c52 as c52, c53 as c53, c54 as c54, c55 as c55, c56 as c56, c57 as c57, c58 as c58, c59 as c59, c60 as c60, c61 as c61, c62 as c62, c63 as c63, c64 as c64, c65 as c65, c66 as c66, c67 as c67, c68 as c68, c69 as c69, c70 as c70, c71 as c71, c72 as c72, c73 as c73, c74 as c74, c75 as c75, c76 as c76, c77 as c77, c78 as c78, c79 as c79, c80 as c80, c81 as c81, c82 as c82, c83 as c83, c84 as c84, c85 as c85, c86 as c86, c87 as c87, c88 as c88, c89 as c89, c90 as c90, c91 as c91, c92 as c92, c93 as c93, c94 as c94, c95 as c95, c96 as c96, c97 as c97, c98 as c98, c99 as c99, c100 as c100, c101 as c101, c102 as c102, c103 as c103, c104 as c104, c105 as c105, c106 as c106, c107 as c107, c108 as c108, c109 as c109, c110 as c110, c111 as c111, c112 as c112, c113 as c113, c114 as c114, c115 as c115, c116 as c116, c117 as c117, c118 as c118, c119 as c119, c120 as c120, c121 as c121, c122 as c122, c123 as c123, c124 as c124, c125 as c125, c126 as c126, c127 as c127, c128 as c128, c129 as c129, c130 as c130, c131 as c131, c132 as c132, c133 as c133, (c84 / (CASE WHEN (c137 IS NOT NULL) THEN (XCOUNT(c137 for c145)) ELSE c108 END)) as c134, (c87 / (CASE WHEN (c137 IS NOT NULL) THEN (XCOUNT(c137 for c145)) ELSE c108 END)) as c135, c136 as c136, c137 as c137, c138 as c138, c139 as c139, c140 as c140, c141 as c141, c142 as c142, c143 as c143, c144 as c144, c145 as c145, CASE WHEN (c137 IS NOT NULL) THEN (XCOUNT(c137 for c145)) ELSE c108 END as c146, CASE WHEN (((c1 IN ('VRGT164013178','VRGT164013176')) and (c43 = 'X4509122825')) and (((CASE WHEN (c142 = -2277740.08) THEN (291.28) ELSE (c282 / CASE WHEN (c137 IS NOT NULL) THEN (XCOUNT(c137 for c145)) ELSE c108 END) END) < -1000000) or ((CASE WHEN (c142 = -2277740.08) THEN (291.28) ELSE (c282 / CASE WHEN (c137 IS NOT NULL) THEN (XCOUNT(c137 for c145)) ELSE c108 END) END) > 1000000))) THEN (-291.28) ELSE ((c283) / CASE WHEN (c137 IS NOT NULL) THEN (XCOUNT(c137 for c145)) ELSE c108 END) END as c147, CASE WHEN (c142 = -2277740.08) THEN (291.28) ELSE (((c282)) / CASE WHEN (c137 IS NOT NULL) THEN (XCOUNT(c137 for c145)) ELSE c108 END) END as c148, CASE WHEN (CASE WHEN (c142 = -2277740.08) THEN (291.28) ELSE (((c282)) / CASE WHEN (c137 IS NOT NULL) THEN (XCOUNT(c137 for c145)) ELSE c108 END) END < 0) THEN (CASE WHEN (c142 = -2277740.08) THEN (291.28) ELSE (((c282)) / CASE WHEN (c137 IS NOT NULL) THEN (XCOUNT(c137 for c145)) ELSE c108 END) END * -1) ELSE CASE WHEN (c142 = -2277740.08) THEN (291.28) ELSE (((c282)) / CASE WHEN (c137 IS NOT NULL) THEN (XCOUNT(c137 for c145)) ELSE c108 END) END END as c149, CASE WHEN ((c84 / (CASE WHEN (c137 IS NOT NULL) THEN (XCOUNT(c137 for c145)) ELSE c108 END)) < 0) THEN (CASE WHEN (CASE WHEN (c142 = -2277740.08) THEN (291.28) ELSE (((c282)) / CASE WHEN (c137 IS NOT NULL) THEN (XCOUNT(c137 for c145)) ELSE c108 END) END < 0) THEN (CASE WHEN (c142 = -2277740.08) THEN (291.28) ELSE (((c282)) / CASE WHEN (c137 IS NOT NULL) THEN (XCOUNT(c137 for c145)) ELSE c108 END) END * -1) ELSE CASE WHEN (c142 = -2277740.08) THEN (291.28) ELSE (((c282)) / CASE WHEN (c137 IS NOT NULL) THEN (XCOUNT(c137 for c145)) ELSE c108 END) END END * -1) ELSE CASE WHEN (CASE WHEN (c142 = -2277740.08) THEN (291.28) ELSE (((c282)) / CASE WHEN (c137 IS NOT NULL) THEN (XCOUNT(c137 for c145)) ELSE c108 END) END < 0) THEN (CASE WHEN (c142 = -2277740.08) THEN (291.28) ELSE (((c282)) / CASE WHEN (c137 IS NOT NULL) THEN (XCOUNT(c137 for c145)) ELSE c108 END) END * -1) ELSE CASE WHEN (c142 = -2277740.08) THEN (291.28) ELSE (((c282)) / CASE WHEN (c137 IS NOT NULL) THEN (XCOUNT(c137 for c145)) ELSE c108 END) END END END as c150, c151 as c151, c152 as c152 from (select c168 as c1, c281 as c2, c280 as c3, c279 as c4, c278 as c5, c277 as c6, c177 as c7, c276 as c8, c275 as c9, c274 as c10, c273 as c11, c272 as c12, c271 as c13, c270 as c14, c269 as c15, c268 as c16, c267 as c17, c266 as c18, c265 as c19, c264 as c20, c195 as c21, c263 as c22, c262 as c23, c261 as c24, c260 as c25, c259 as c26, c258 as c27, c257 as c28, c256 as c29, c255 as c30, c254 as c31, c253 as c32, c252 as c33, c251 as c34, c250 as c35, c249 as c36, c248 as c37, c247 as c38, c246 as c39, c245 as c40, c244 as c41, c243 as c42, c167 as c43, c242 as c44, c241 as c45, c240 as c46, c239 as c47, c238 as c48, c237 as c49, c236 as c50, c235 as c51, c234 as c52, c233 as c53, c232 as c54, c231 as c55, c230 as c56, c229 as c57, c228 as c58, c227 as c59, c226 as c60, c196 as c61, c225 as c62, c224 as c63, c223 as c64, c222 as c65, c221 as c66, c220 as c67, c219 as c68, c218 as c69, c217 as c70, c216 as c71, c215 as c72, c214 as c73, c213 as c74, c212 as c75, c211 as c76, c210 as c77, c209 as c78, c208 as c79, c207 as c80, c206 as c81, c205 as c82, c204 as c83, c165 as c84, c203 as c85, c202 as c86, c176 as c87, c177 as c88, '1' as c89, c160 as c90, c201 as c91, c200 as c92, c199 as c93, c198 as c94, c197 as c95, '' as c96, '' as c97, '' as c98, c196 as c99, 'Teile' as c100, 'Teile' as c101, c195 as c102, c194 as c103, '' as c104, '' as c105, 'Teile' as c106, c193 as c107, 1 as c108, XCOUNT(c254 for c159) as c109, 1 / (XCOUNT(c254 for c159)) as c110, '' as c111, c192 as c112, c191 as c113, c190 as c114, c189 as c115, c188 as c116, c187 as c117, c186 as c118, c185 as c119, c184 as c120, c183 as c121, c182 as c122, c181 as c123, c180 as c124, c179 as c125, ('Umsatz FW gesamt') as c126, c178 as c127, c160 as c128, '' as c129, c178 as c130, '' as c131, c177 as c132, (('Umsatz FW gesamt')) as c133, c175 as c136, c163 as c137, c174 as c138, c173 as c139, c172 as c140, c171 as c141, c164 as c142, c170 as c143, c169 as c144, c158 as c145, c161 as c151, c160 as c152, c162 as c282, c166 as c283 from (select (T1."No_" || '-' || (od_left((cast_numberToString(cast_integer(T2."Line No_"))),7)) || '-' || T6."Item No_") as c158, ((T1."Service Order No_" || ' - ' || T1."Bill-to Name")) as c159, ((CASE WHEN (T1."Location Code" = 'MM') THEN ('10') WHEN (T1."Location Code" = 'VÖH') THEN ('20') WHEN (T1."Location Code" = 'KRU') THEN ('30') WHEN (T1."Location Code" = 'ULM') THEN ('40') WHEN (T1."Location Code" = 'LL') THEN ('50') WHEN (T1."Location Code" = 'GZ') THEN ('55') WHEN (T1."Location Code" = 'AAM') THEN ('60') WHEN (T1."Location Code" = 'LEH') THEN ('70') ELSE null END)) as c160, CASE WHEN (((CASE WHEN (T1."Location Code" = 'MM') THEN ('10') WHEN (T1."Location Code" = 'VÖH') THEN ('20') WHEN (T1."Location Code" = 'KRU') THEN ('30') WHEN (T1."Location Code" = 'ULM') THEN ('40') WHEN (T1."Location Code" = 'LL') THEN ('50') WHEN (T1."Location Code" = 'GZ') THEN ('55') WHEN (T1."Location Code" = 'AAM') THEN ('60') WHEN (T1."Location Code" = 'LEH') THEN ('70') ELSE null END)) IN ('60','70')) THEN ('2') ELSE ('1') END as c161, ((cast_float(T6."Valued Quantity"))) * ((cast_float(T6."Cost per Unit"))) as c162, T6."Item No_" as c163, (cast_float(T6."Cost per Unit")) as c164, (cast_float(T2."Amount")) as c165, (((cast_float(T6."Valued Quantity"))) * ((cast_float(T6."Cost per Unit")))) * -1 as c166, T2."No_" as c167, T1."No_" as c168, (cast_float(T6."Cost Posted to G_L")) as c169, (cast_float(T6."Adjusted Cost")) as c170, T6."Invoiced Quantity" as c171, (cast_float(T6."Valued Quantity")) as c172, T6."Item Ledger Entry No_" as c173, T6."Posting Date" as c174, T6."Entry No_" as c175, ((cast_float(T2."Quantity"))) * ((cast_float(T2."Unit Cost"))) as c176, T1."Posting Date" as c177, (CASE WHEN (((CASE WHEN (T5."BMW Parts Type" IN ('1','2')) THEN ('Teileart 1 - 2') WHEN (T5."BMW Parts Type" IN ('3','4','5','6','7','8','9')) THEN ('Teileart 3 - 9') ELSE ('Teileart fehlt') END) = 'Teileart 1 - 2') and (T2."Item Group Code" IN ('D','E','23','26','27','30','31','32','33','24','25','28','29'))) THEN ('Umsatz FW TA1-2 D/E') WHEN (((CASE WHEN (T5."BMW Parts Type" IN ('1','2')) THEN ('Teileart 1 - 2') WHEN (T5."BMW Parts Type" IN ('3','4','5','6','7','8','9')) THEN ('Teileart 3 - 9') ELSE ('Teileart fehlt') END) = 'Teileart 1 - 2') and (T2."Item Group Code" IN ('F','G','H','I','K','34','35','36','37','38','39','41','42','43','44','45','46','47','48','49','50','51','52','53','54','55','56','57','58','59','60','61','62','63','65','66','67','69','71','73','74','75','98','99'))) THEN ('Umsatz FW TA1-2 F-K') WHEN (T1."Item Sales Price Group" = 'LACK') THEN ('Umsatz Lack') ELSE ('Umsatz FW Rest') END) as c178, CASE WHEN (T5."Item Group Code" IN ('A','C','B')) THEN ('Artikelgruppe A - C') WHEN (T5."Item Group Code" IN ('E','G','H','F','D','I','K','J')) THEN ('Artikelgruppe D - K') ELSE ('Teileart fehlt/Rest') END as c179, CASE WHEN (T5."BMW Parts Type" IN ('1','2')) THEN ('Teileart 1 - 2') WHEN (T5."BMW Parts Type" IN ('3','4','5','6','7','8','9')) THEN ('Teileart 3 - 9') ELSE ('Teileart fehlt') END as c180, T5."Item Group Code" as c181, T5."BMW Parts Type" as c182, T5."Commission Group" as c183, T5."Inventory Posting Group" as c184, T5."Class" as c185, T5."Description" as c186, T5."No_" as c187, T4."Customer Group Code" as c188, T4."Customer Type" as c189, T4."Customer Posting Group" as c190, T4."Name" as c191, T4."No_" as c192, CASE WHEN ((T3."First Name" || ' ' || T3."Last Name") IS NOT NULL) THEN (T1."Service Order No_" || ' - ' || (T3."First Name" || ' ' || T3."Last Name") || ' - ' || (asciiz(extract(YEAR FROM T1."Posting Date"),4) || '-' || asciiz(extract(MONTH FROM T1."Posting Date"),2) || '-' || asciiz(extract(DAY FROM T1."Posting Date"),2)) || ' - ' || T1."Bill-to Name") WHEN ((T3."First Name" || ' ' || T3."Last Name") IS NULL) THEN (T1."Service Order No_" || ' - ' || (asciiz(extract(YEAR FROM T1."Posting Date"),4) || '-' || asciiz(extract(MONTH FROM T1."Posting Date"),2) || '-' || asciiz(extract(DAY FROM T1."Posting Date"),2)) || ' - ' || T1."Bill-to Name") ELSE null END as c193, T1."Sell-to Customer No_" || ' - ' || T1."Bill-to Name" as c194, T1."Gen_ Bus_ Posting Group" as c195, T2."Make Code" as c196, T1."Service Order No_" || ' - ' || T1."Bill-to Name" as c197, T3."Department Code" as c198, T3."First Name" || ' ' || T3."Last Name" as c199, T3."Last Name" as c200, T3."First Name" as c201, ((cast_float(T2."Amount"))) as c202, (cast_float(T2."Unit Cost")) as c203, (cast_float(T2."Line Discount Amount")) as c204, (cast_float(T2."Unit Cost (LCY)")) as c205, (cast_float(T2."Unit Price")) as c206, (cast_float(T2."Quantity")) as c207, T2."Item Group Code" as c208, T2."Service Order Line No_" as c209, T2."Service Order No_" as c210, T2."Item Type" as c211, T2."Order Type" as c212, T2."Branch Book No_" as c213, T2."Posting Date" as c214, T2."Order Line No_" as c215, T2."Order No_" as c216, T2."Quantity (Base)" as c217, T2."Unit of Measure Code" as c218, T2."Qty_ per Unit of Measure" as c219, T2."Variant Code" as c220, T2."Book No_" as c221, T2."Unit Cost" as c222, T2."Area" as c223, T2."Allow Quantity Disc_" as c224, T2."Price Group Code" as c225, T2."Department Code" as c226, T2."Allow Invoice Disc_" as c227, T2."Amount Including VAT" as c228, T2."Amount" as c229, T2."Line Discount Amount" as c230, T2."Line Discount %" as c231, T2."Quantity Disc_ %" as c232, T2."VAT %" as c233, T2."Unit Cost (LCY)" as c234, T2."Unit Price" as c235, T2."Quantity" as c236, T2."Unit of Measure" as c237, T2."Description 2" as c238, T2."Description" as c239, T2."Quantity Disc_ Code" as c240, T2."Posting Group" as c241, T2."Location Code" as c242, T2."Type" as c243, T2."Sell-to Customer No_" as c244, T2."Line No_" as c245, T2."Document No_" as c246, T1."VIN" as c247, T1."Branch Code" as c248, T1."Service Order Line No_" as c249, T1."Service Order No_ 2" as c250, T1."Customer Group Code" as c251, T1."Show Discount" as c252, T1."Item Sales Price Group" as c253, T1."Service Order No_" as c254, T1."Order Type" as c255, T1."User ID" as c256, T1."Order No_ Series" as c257, T1."No_ Series" as c258, T1."Payment Method Code" as c259, T1."Area" as c260, T1."Document Date" as c261, T1."Sell-to Customer Name 2" as c262, T1."Sell-to Customer Name" as c263, T1."On Hold" as c264, T1."Order No_" as c265, T1."Salesperson Code" as c266, T1."Cust__Item Disc_ Gr_" as c267, T1."Invoice Disc_ Code" as c268, T1."Customer Posting Group" as c269, T1."Make Code" as c270, T1."Department Code" as c271, T1."Location Code" as c272, T1."Pmt_ Discount Date" as c273, T1."Payment Discount %" as c274, T1."Due Date" as c275, T1."Posting Description" as c276, T1."Order Date" as c277, T1."Bill-to Name 2" as c278, T1."Bill-to Name" as c279, T1."Bill-to Customer No_" as c280, T1."Sell-to Customer No_" as c281 from (("NAVISION"."import"."Sales_Invoice_Header" T1 left outer join "NAVISION"."import"."Employee" T3 on (T1."Salesperson Code" = T3."No_") and (T1."Client_DB" = T3."Client_DB")) left outer join "NAVISION"."import"."Customer" T4 on (T1."Bill-to Customer No_" = T4."No_") and (T1."Client_DB" = T4."Client_DB")), (("NAVISION"."import"."Sales_Invoice_Line" T2 left outer join "NAVISION"."import"."Item" T5 on (T2."No_" = T5."No_") and (T2."Client_DB" = T5."Client_DB")) left outer join "NAVISION"."import"."Value_Ledger_Entry" T6 on ((T6."Document No_" = T2."Document No_") and (T6."Item No_" = T2."No_")) and (T6."Client_DB" = T2."Client_DB")) where ((T1."No_" = T2."Document No_") and (T1."Client_DB" = T2."Client_DB")) and (((T1."Posting Date" >= TIMESTAMP '2021-01-01 00:00:00.000') and ((T1."No_" LIKE 'VRT%') or (T1."No_" LIKE 'VRGT%'))) and (T1."Item Sales Price Group" IN ('44','51','60','61','65','66','67','68','50','52','53','70','LACK','AL-KO','GROßKUNDE','KUNDE10','SOLOPLAN'))) ) D1 ) D4 order by c1 asc,c145 asc,c18 asc,c31 asc,c93 asc END SQL COLUMN,0,No COLUMN,1,Sell-to Customer No COLUMN,2,Bill-to Customer No COLUMN,3,Bill-to Name COLUMN,4,Bill-to Name 2 COLUMN,5,Order Date COLUMN,6,Posting Date COLUMN,7,Posting Description COLUMN,8,Due Date COLUMN,9,Payment Discount % COLUMN,10,Pmt Discount Date COLUMN,11,Location Code COLUMN,12,Department Code COLUMN,13,Make Code COLUMN,14,Customer Posting Group COLUMN,15,Invoice Disc Code COLUMN,16,Cust Item Disc Gr COLUMN,17,Salesperson Code COLUMN,18,Order No COLUMN,19,On Hold COLUMN,20,Gen Bus Posting Group COLUMN,21,Sell-to Customer Name COLUMN,22,Sell-to Customer Name 2 COLUMN,23,Document Date COLUMN,24,Area COLUMN,25,Payment Method Code COLUMN,26,No Series COLUMN,27,Order No Series COLUMN,28,User Id COLUMN,29,Order Type COLUMN,30,Service Order No COLUMN,31,Item Sales Price Group COLUMN,32,Show Discount COLUMN,33,Customer Group Code COLUMN,34,Service Order No 2 COLUMN,35,Service Order Line No COLUMN,36,Branch Code COLUMN,37,Vin COLUMN,38,Document No COLUMN,39,Line No COLUMN,40,Sell-to Customer No COLUMN,41,Type COLUMN,42,No COLUMN,43,Location Code COLUMN,44,Posting Group COLUMN,45,Quantity Disc Code COLUMN,46,Description COLUMN,47,Description 2 COLUMN,48,Unit Of Measure COLUMN,49,Quantity COLUMN,50,Unit Price COLUMN,51,Unit Cost (lcy) COLUMN,52,Vat % COLUMN,53,Quantity Disc % COLUMN,54,Line Discount % COLUMN,55,Line Discount Amount COLUMN,56,Amount COLUMN,57,Amount Including Vat COLUMN,58,Allow Invoice Disc COLUMN,59,Department Code COLUMN,60,Make Code COLUMN,61,Price Group Code COLUMN,62,Allow Quantity Disc COLUMN,63,Area COLUMN,64,Unit Cost COLUMN,65,Book No COLUMN,66,Variant Code COLUMN,67,Qty Per Unit Of Measure COLUMN,68,Unit Of Measure Code COLUMN,69,Quantity (base) COLUMN,70,Order No COLUMN,71,Order Line No COLUMN,72,Posting Date COLUMN,73,Branch Book No COLUMN,74,Order Type COLUMN,75,Item Type COLUMN,76,Service Order No COLUMN,77,Service Order Line No COLUMN,78,Item Group Code COLUMN,79,Menge COLUMN,80,Unit Preis COLUMN,81,Unit Kosten (LCY) COLUMN,82,Line Rabatt Betrag COLUMN,83,Betrag COLUMN,84,Kosten COLUMN,85,Umsatz Teile Service COLUMN,86,Einsatz Teile Service COLUMN,87,Invoice Date COLUMN,88,Hauptbetrieb COLUMN,89,Standort COLUMN,90,First Name COLUMN,91,Last Name COLUMN,92,Serviceberater COLUMN,93,Department Code COLUMN,94,Order Number COLUMN,95,Fabrikat COLUMN,96,Model COLUMN,97,Fahrzeug COLUMN,98,Marke COLUMN,99,Umsatzart COLUMN,100,Auftragsart COLUMN,101,Kundenart COLUMN,102,Kunde COLUMN,103,Function Code COLUMN,104,Monteur COLUMN,105,Auftragsart_1 COLUMN,106,Order Number_Rg_Ausg COLUMN,107,DG_1 COLUMN,108,DG_2 COLUMN,109,Durchgänge COLUMN,110,Rg_Ausgang_Arb_Pos COLUMN,111,No COLUMN,112,Name COLUMN,113,Customer Posting Group COLUMN,114,Customer Type COLUMN,115,Customer Group Code COLUMN,116,No COLUMN,117,Description COLUMN,118,Class COLUMN,119,Inventory Posting Group COLUMN,120,Commission Group COLUMN,121,Bmw Parts Type COLUMN,122,Item Group Code_Teilestamm COLUMN,123,Teileart COLUMN,124,Artikelgruppe COLUMN,125,Vstufe 1 COLUMN,126,Zeile mit Bez COLUMN,127,Betrieb Nr COLUMN,128,Konto COLUMN,129,Konto Nr COLUMN,130,Text COLUMN,131,Jahr COLUMN,132,Bereich COLUMN,133,Umsatzerlöse COLUMN,134,VAK COLUMN,135,Entry No_Value_ledger_entry COLUMN,136,Item No_Value_ledger_entry COLUMN,137,Posting Date_Value_ledger_entry COLUMN,138,Item Ledger Entry No_Value_ledger_entry COLUMN,139,Valued Quantity_Value_ledger_entry COLUMN,140,Invoiced Quantity_Value_ledger_entry COLUMN,141,Cost Per Unit_Value_ledger_entry COLUMN,142,Adjusted Cost_Value_ledger_entry COLUMN,143,Cost Posted To G L_Value_ledger_entry COLUMN,144,No_Item_No_Value_ledger_entry COLUMN,145,Anzahl_Sätze_Value_ledger_entry COLUMN,146,VAK_Wertposten_ori COLUMN,147,VAK_Wertposten_neu COLUMN,148,VAK_Wertposten_neu_1 COLUMN,149,VAK_Wertposten COLUMN,150,Hauptbetrieb_ID COLUMN,151,Standort_ID