COGNOS QUERY
STRUCTURE,1,1
DATABASE,O21
DATASOURCENAME,C:\GAPS\Portal\System\IQD\NW\NW_GW_VK_Stk.imr
TITLE,NW_GW_VK_Stk.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,
	   XMAX(c105 for c1) as c106,
	   c107 as c107,
	   c108 as c108,
	   c109 as c109
from 
(select c113 as c1,
	   c206 as c2,
	   c205 as c3,
	   c204 as c4,
	   c203 as c5,
	   c202 as c6,
	   c201 as c7,
	   c200 as c8,
	   c199 as c9,
	   c198 as c10,
	   c197 as c11,
	   c196 as c12,
	   c195 as c13,
	   c194 as c14,
	   c193 as c15,
	   c192 as c16,
	   c191 as c17,
	   c190 as c18,
	   c189 as c19,
	   c188 as c20,
	   c187 as c21,
	   c137 as c22,
	   c186 as c23,
	   c185 as c24,
	   c139 as c25,
	   c184 as c26,
	   c183 as c27,
	   c182 as c28,
	   c181 as c29,
	   c180 as c30,
	   c179 as c31,
	   c178 as c32,
	   c177 as c33,
	   c176 as c34,
	   c175 as c35,
	   c174 as c36,
	   c173 as c37,
	   c172 as c38,
	   c171 as c39,
	   c170 as c40,
	   c123 as c41,
	   c169 as c42,
	   c168 as c43,
	   c167 as c44,
	   c166 as c45,
	   c165 as c46,
	   c164 as c47,
	   c163 as c48,
	   c162 as c49,
	   c161 as c50,
	   c160 as c51,
	   c159 as c52,
	   c134 as c53,
	   c158 as c54,
	   c157 as c55,
	   c156 as c56,
	   c155 as c57,
	   c154 as c58,
	   c153 as c59,
	   c121 as c60,
	   c152 as c61,
	   c151 as c62,
	   c150 as c63,
	   c135 as c64,
	   c149 as c65,
	   c148 as c66,
	   c147 as c67,
	   c146 as c68,
	   c145 as c69,
	   c144 as c70,
	   c143 as c71,
	   c142 as c72,
	   c136 as c73,
	   c141 as c74,
	   c140 as c75,
	   c139 as c76,
	   '1' as c77,
	   c138 as c78,
	   c137 as c79,
	   c136 as c80,
	   c135 as c81,
	   c121 as c82,
	   c134 as c83,
	   c133 as c84,
	   c132 as c85,
	   c131 as c86,
	   c130 as c87,
	   '' as c88,
	   c129 as c89,
	   c128 as c90,
	   c127 as c91,
	   c126 as c92,
	   c125 as c93,
	   c124 as c94,
	   c124 as c95,
	   c123 as c96,
	   c122 as c97,
	   c121 as c98,
	   c120 as c99,
	   1 as c100,
	   c119 as c101,
	   c118 as c102,
	   c117 as c103,
	   c116 as c104,
	   c115 as c105,
	   c114 as c107,
	   '10 - Menge' as c108,
	   '10 - Menge' as c109,
	   XMAX(c115 for c113) as c110
from 
(select T1."UNIT_NUMBER" as c113,
	   (od_left(T1."BOOK_KEEPING_CODE",1)) as c114,
	   T12."UNIQUE_IDENT" as c115,
	   CASE WHEN (T10."DESCRIPTION" IN ('Opel','Volvo')) THEN (T10."DESCRIPTION") ELSE ('Fremdfabrikat') END as c116,
	   (od_left(T12."DEPARTMENT",2)) as c117,
	   T12."DEPARTMENT" as c118,
	   CASE WHEN (T1."RECEPTION_DATE" IS NULL) THEN ((extract(DAY FROM T1."SALE_DATE" - T1."PURCH_DATE"))) ELSE ((extract(DAY FROM T1."SALE_DATE" - T1."RECEPTION_DATE"))) END as c119,
	   T5."SEL_NAME" || ' / ' || (T6."CUSTOMER_NUMBER" || '- ' || T6."NAME") as c120,
	   T8."MODEL_TEXT" as c121,
	   CASE WHEN (T11."SEL_NAME" IS NULL) THEN (' - ' || ' / ' || T1."PREV_OWNER") ELSE (T11."SEL_NAME" || ' / ' || T1."PREV_OWNER") END as c122,
	   T1."PREV_OWNER" as c123,
	   T11."SEL_NAME" as c124,
	   (T1."UNIT_NUMBER" || ' - ' || T8."CHASSIS_NUMBER") || ' - ' || T1."VEHICLE_TYPE" as c125,
	   T1."UNIT_NUMBER" || ' - ' || T1."OWNER" || ' - ' || (asciiz(extract(YEAR FROM T8."ORIG_INV_DATE"),4) || '-' || asciiz(extract(MONTH FROM T8."ORIG_INV_DATE"),2) || '-' || asciiz(extract(DAY FROM T8."ORIG_INV_DATE"),2)) as c126,
	   T1."UNIT_NUMBER" || ' - ' || T8."CHASSIS_NUMBER" as c127,
	   CASE WHEN (T1."ECC_STATUS" = '21') THEN ('21 - Vorlauf') WHEN (T1."ECC_STATUS" = '25') THEN ('25 - für Kd best. FZG') WHEN (T1."ECC_STATUS" = '41') THEN ('41 - Bestand') WHEN (T1."ECC_STATUS" = '44') THEN ('44 - am Hof nicht fakt.') WHEN (T1."ECC_STATUS" = '64') THEN ('64 - verkauft') ELSE null END as c128,
	   T8."COLOUR_CODE" || ' - ' || T8."COLOUR_CF" as c129,
	   T6."CUSTOMER_GROUP" || ' - ' || T7."CUST_GROUP_SPECIFY" as c130,
	   T6."CUSTOMER_NUMBER" || '- ' || T6."NAME" as c131,
	   CASE WHEN (T2."VEHICLE_TYPE" IS NULL) THEN (T1."VEHICLE_TYPE") ELSE (T2."VEHICLE_TYPE" || ' - ' || T2."VEHICLE_TYPE_TEXT") END as c132,
	   CASE WHEN (T2."VEHICLE_TYPE" IN ('K','M','N','V','T','V')) THEN ('Neuwagen') WHEN (T2."VEHICLE_TYPE" IN ('D','R','G')) THEN ('Gebrauchtwagen') ELSE null END as c133,
	   T8."CHASSIS_NUMBER" as c134,
	   T9."MOD_LIN_SPECIFY" as c135,
	   T10."DESCRIPTION" as c136,
	   T5."SEL_NAME" as c137,
	   (od_left(T1."SALES_DEPARTMENT",2)) as c138,
	   T1."SALE_DATE" as c139,
	   T8."LATEST_INV_DATE" as c140,
	   T8."ORIG_INV_DATE" as c141,
	   T10."GLOBAL_MAKE_CD" as c142,
	   T8."MAKE_CD" as c143,
	   T8."MAKE" as c144,
	   T8."COLOUR_CODE" as c145,
	   T8."DRIVE_CODE" as c146,
	   T8."MOTOR_CODE" as c147,
	   T8."MILEAGE" as c148,
	   T8."WORKSHOP_MODEL" as c149,
	   T9."MODEL_LINE" as c150,
	   T8."MODEL_LINE" as c151,
	   T8."COLOUR_CF" as c152,
	   T8."SALESMAN_SALE" as c153,
	   T8."SALESMAN_BUY" as c154,
	   T8."ARRIVAL_DATE" as c155,
	   T8."LATEST_REG_DATE" as c156,
	   T8."FIRST_REG_DATE" as c157,
	   T8."OWNER_CODE" as c158,
	   T8."REGISTER_NUMBER" as c159,
	   T1."CONTRACT_DATE" as c160,
	   T1."ORDER_CONFIRM_DATE" as c161,
	   T1."ORDER_ARRIVAL_DATE" as c162,
	   T7."CUST_GROUP_SPECIFY" as c163,
	   T7."CUSTOMER_GROUP" as c164,
	   T6."CUSTOMER_GROUP" as c165,
	   T6."NAME" as c166,
	   T6."CUSTOMER_NUMBER" as c167,
	   T1."ACCOUNT_SALES" as c168,
	   T1."ACCOUNT_PURCHASE" as c169,
	   T1."OWNER" as c170,
	   T1."LOCATION_CODE" as c171,
	   T1."PA_NUMBER" as c172,
	   T1."BUYING_ORDER_DATE" as c173,
	   T1."BUYING_ORDER_NO" as c174,
	   T1."STOCK_DAYS" as c175,
	   T1."REG_FEE" as c176,
	   T1."SALES_PRICE_UNIT" as c177,
	   T1."COST_UNIT" as c178,
	   T1."PURCH_PRICE_UNIT" as c179,
	   T1."BUD_COST" as c180,
	   T1."BUD_DEDUCT_FEE" as c181,
	   T1."BUD_REG_FEE" as c182,
	   T1."BUD_PURCH_PRICE" as c183,
	   T1."BUD_SALE_DET" as c184,
	   T1."SALE_INV_NUMBER" as c185,
	   T5."SEL_FAMILY_NAME" as c186,
	   T5."SELLER_CODE" as c187,
	   T1."SALE_SALESMAN" as c188,
	   T4."DESCRIPTION" as c189,
	   T4."DEPARTMENT_TYPE_ID" as c190,
	   T1."SALES_DEPARTMENT" as c191,
	   T1."RECEPTION_DATE" as c192,
	   T1."PURCH_DATE" as c193,
	   T1."PURCH_SALSMAN_CODE" as c194,
	   T1."PURCH_DEPARTMENT" as c195,
	   T1."MILEAGE" as c196,
	   T3."SPECIFY" as c197,
	   T3."BOOK_KEEPING_CODE" as c198,
	   T1."BOOK_KEEPING_CODE" as c199,
	   T1."DEPRECIATION" as c200,
	   T1."CAR_CREATION_DATE" as c201,
	   T2."VEHICLE_TYPE_TEXT" as c202,
	   T2."VEHICLE_TYPE" as c203,
	   T1."VEHICLE_TYPE" as c204,
	   T1."ECC_STATUS" as c205,
	   T1."BASIS_NUMBER" as c206
from ((((((((((("deop01"."dbo"."UNIT_FILE" T1 left outer join "deop01"."dbo"."vPP5R" T2 on T1."VEHICLE_TYPE" = T2."VEHICLE_TYPE") left outer join "deop01"."dbo"."vPP5M" T3 on T1."BOOK_KEEPING_CODE" = T3."BOOK_KEEPING_CODE") left outer join "deop01"."dbo"."DEPARTMENT_TYPE" T4 on T1."SALES_DEPARTMENT" = T4."DEPARTMENT_TYPE_ID") left outer join "deop01"."dbo"."vPP43" T5 on T1."SALE_SALESMAN" = T5."SELLER_CODE") left outer join "deop01"."dbo"."CUSTOMER" T6 on T1."ACCOUNT_SALES" = T6."CUSTOMER_NUMBER") left outer join "deop01"."dbo"."vPP48" T7 on T6."CUSTOMER_GROUP" = T7."CUSTOMER_GROUP") left outer join "deop01"."dbo"."VEHICLE" T8 on T1."BASIS_NUMBER" = T8."BASIS_NUMBER") left outer join "deop01"."dbo"."vPP5Q" T9 on (T8."MODEL_LINE" = T9."MODEL_LINE") and (T8."MAKE_CD" = T9."MAKE_CD")) left outer join "deop01"."dbo"."GLOBAL_MAKE" T10 on T8."MAKE_CD" = T10."GLOBAL_MAKE_CD") left outer join "deop01"."dbo"."vPP43" T11 on T1."PURCH_SALSMAN_CODE" = T11."SELLER_CODE") left outer join "deop01"."dbo"."UNIT_CHANGE_HIST" T12 on (T12."UNIT_NUMBER" = T1."UNIT_NUMBER") and (T12."DEPARTMENT" <> ' '))
where ((T1."ECC_STATUS" = '64') and (T1."SALE_DATE" >= TIMESTAMP '2016-01-01 00:00:00.000'))
) D2
) D1
where (c105 = c110)
order by c1 asc

END SQL
COLUMN,0,Unit Number
COLUMN,1,Basis Number
COLUMN,2,Ecc Status
COLUMN,3,Vehicle Type
COLUMN,4,Vehicle Type_vpp5r
COLUMN,5,Vehicle Type Text_vpp5r
COLUMN,6,Car Creation Date
COLUMN,7,Depreciation
COLUMN,8,Book Keeping Code
COLUMN,9,Book Keeping Code_vpp5m
COLUMN,10,Specify_vpp5m
COLUMN,11,Mileage
COLUMN,12,Purch Department
COLUMN,13,Purch Salsman Code
COLUMN,14,Purch Date
COLUMN,15,Reception Date
COLUMN,16,Sales Department
COLUMN,17,Department Type Id_Dep
COLUMN,18,Description_Dep
COLUMN,19,Sale Salesman
COLUMN,20,Seller Code_vpp43
COLUMN,21,Sel Name_vpp43
COLUMN,22,Sel Family Name_vpp43
COLUMN,23,Sale Inv Number
COLUMN,24,Sale Date
COLUMN,25,Bud Sale Det
COLUMN,26,Bud Purch Price
COLUMN,27,Bud Reg Fee
COLUMN,28,Bud Deduct Fee
COLUMN,29,Bud Cost
COLUMN,30,Purch Price Unit
COLUMN,31,Cost Unit
COLUMN,32,Sales Price Unit
COLUMN,33,Reg Fee
COLUMN,34,Stock Days
COLUMN,35,Buying Order No
COLUMN,36,Buying Order Date
COLUMN,37,Pa Number
COLUMN,38,Location Code
COLUMN,39,Owner
COLUMN,40,Prev Owner
COLUMN,41,Account Purchase
COLUMN,42,Account Sales
COLUMN,43,Customer Number_Cust
COLUMN,44,Name_Cust
COLUMN,45,Customer Group_Cust
COLUMN,46,Customer Group_vpp48
COLUMN,47,Cust Group Specify_vpp48
COLUMN,48,Order Arrival Date
COLUMN,49,Order Confirm Date
COLUMN,50,Contract Date
COLUMN,51,Register Number
COLUMN,52,Chassis Number
COLUMN,53,Owner Code
COLUMN,54,First Reg Date
COLUMN,55,Latest Reg Date
COLUMN,56,Arrival Date
COLUMN,57,Salesman Buy
COLUMN,58,Salesman Sale
COLUMN,59,Model Text
COLUMN,60,Colour Cf
COLUMN,61,Model Line
COLUMN,62,Model Line_vpp5q
COLUMN,63,Mod Lin Specify_vpp5q
COLUMN,64,Workshop Model
COLUMN,65,Mileage
COLUMN,66,Motor Code
COLUMN,67,Drive Code
COLUMN,68,Colour Code
COLUMN,69,Make
COLUMN,70,Make Cd
COLUMN,71,Global Make Cd
COLUMN,72,Description_Global_Make
COLUMN,73,Orig Inv Date
COLUMN,74,Latest Inv Date
COLUMN,75,Invoice Date
COLUMN,76,Hauptbetrieb
COLUMN,77,Standort_Verkaufskostenstelle
COLUMN,78,Verkäufer
COLUMN,79,Fabrikat_ori
COLUMN,80,Model
COLUMN,81,Modellbez
COLUMN,82,Fahrgestellnr
COLUMN,83,Fahrzeugart
COLUMN,84,Fahrzeugtyp
COLUMN,85,Kunde
COLUMN,86,Kundenart
COLUMN,87,Geschäftsart
COLUMN,88,Farbe
COLUMN,89,ECC_Status_Text
COLUMN,90,FZG
COLUMN,91,FZG_1
COLUMN,92,FZG_Liste_1
COLUMN,93,Sel Name_EK_vpp43
COLUMN,94,Einkäufer
COLUMN,95,Vorbesitzer
COLUMN,96,FZG_Liste_2
COLUMN,97,FZG_Liste_3
COLUMN,98,FZG_Liste_4
COLUMN,99,Menge
COLUMN,100,Standtage
COLUMN,101,Department_unit_change_hist
COLUMN,102,Standort
COLUMN,103,Fabrikat
COLUMN,104,Unique Ident_unit_change_hist
COLUMN,105,Maximum_Unique_Ident
COLUMN,106,Book Keeping Code_1
COLUMN,107,TR Code
COLUMN,108,TR Text

