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

