COGNOS QUERY
STRUCTURE,1,1
DATABASE,O21
DATASOURCENAME,D:\GAPS\Portal\System\IQD\Belege\GuV_8_O21_STK.imr
TITLE,GuV_8_O21_STK.imr
BEGIN SQL
select T1."ACCT_NR" as c1,
	   T1."LEDGER_ACCTS_NAME" as c2,
	   T1."LEDGER_ACCTS_NAME2" as c3,
	   T1."HANDLER" as c4,
	   T1."DEPT_SPLIT" as c5,
	   T1."TYPE_ACCTT" as c6,
	   T2."ACCT_NO" as c7,
	   T2."BOOKKEEP_DATE" as c8,
	   T2."BOOKKEEP_PERIOD" as c9,
	   T2."DOCUMENT_NO" as c10,
	   T2."ORIGIN" as c11,
	   T2."STATUS" as c12,
	   T2."DEBIT_AMOUNT" as c13,
	   T2."CREDIT_AMOUNT" as c14,
	   T2."DEBIT_QUANTITY" as c15,
	   T2."CREDIT_QUANTITY" as c16,
	   T2."AA_TRTYPE" as c17,
	   T2."DEPARTMENT" as c18,
	   T2."STOCK" as c19,
	   T2."MAKE_FAMILY" as c20,
	   T2."MAKE" as c21,
	   T2."VEHICLE_TYPE" as c22,
	   T2."MODEL_LINE" as c23,
	   T2."FACTORY_MODEL" as c24,
	   T2."WORKSHOP_MODEL" as c25,
	   T2."PRODUCT_GROUP" as c26,
	   T2."REPAIR_GROUP" as c27,
	   T2."KIT_GROUP" as c28,
	   T2."TIME_CODE" as c29,
	   T2."INT_VOUCHER_NO" as c30,
	   T2."BALANCING_MARK" as c31,
	   T2."USED_VEH_DEST_CODE" as c32,
	   T2."USE_OF_VEHICLE" as c33,
	   T2."ACCT_NO_NEXT_CHART" as c34,
	   T3."REFERENCE_IDENT" as c35,
	   T3."TRANSACT_DATE" as c36,
	   T3."HANDLER" as c37,
	   T3."PROGRAM" as c38,
	   T3."FUNCTION_CODE" as c39,
	   T3."MODUL" as c40,
	   T3."DOCUMENT_KEY" as c41,
	   T3."COMMENT" as c42,
	   T4."DEPARTMENT_TYPE_ID" as c43,
	   T4."DESCRIPTION" as c44,
	   T4."DEPARTMENT_GROUP" as c45,
	   T5."AA_TRTYPE_ID" as c46,
	   T5."DESCRIPTION" as c47,
	   T5."OWN_DESCRIPTION" as c48,
	   '1' as c49,
	   CASE WHEN ((T1."ACCT_NR" LIKE '2%') and (T2."DEPARTMENT" = ' ')) THEN ('01') ELSE ((od_left(T4."DEPARTMENT_TYPE_ID",2))) END as c50,
	   CASE WHEN ((T1."ACCT_NR" LIKE '2%') and (T2."DEPARTMENT" = '')) THEN ('1') ELSE ((substring(T4."DEPARTMENT_TYPE_ID" from 3 for 1))) END as c51,
	   (database()) as c52,
	   T2."DEBIT_QUANTITY" + T2."CREDIT_QUANTITY" as c53,
	   CASE WHEN ((extract(DAY FROM (now()) - T2."BOOKKEEP_DATE")) <= 90) THEN ((od_left((cast_numberToString(cast_integer(T2."DOCUMENT_NO"))),7)) || ' - ' || T3."COMMENT") ELSE ('älter 90 Tage') END as c54,
	   (rtrim(T1."ACCT_NR")) || '_STK' as c55,
	   'STK' as c56,
	   T6."ORDER_NUMBER" as c57,
	   T6."LINE_NUMBER" as c58,
	   T6."INV_TIME" as c59,
	   T6."INV_TIME_INT" as c60,
	   T6."MAKE_TIME_UNIT" as c61,
	   'STK' as c62,
	   'kein EB' as c63
from "deop01"."dbo"."ACCOUNT_INFO" T1,
	(("deop01"."dbo"."ACCT_DOC_KEY" T2 left outer join "deop01"."dbo"."DEPARTMENT_TYPE" T4 on T2."DEPARTMENT" = T4."DEPARTMENT_TYPE_ID") left outer join "deop01"."dbo"."AA_TRTYPE" T5 on T2."AA_TRTYPE" = T5."AA_TRTYPE_ID"),
	(("deop01"."dbo"."ACCT_DOC_DATA" T3 left outer join "deop01"."dbo"."ACCT_DOC_SALESCLAS" T7 on T3."REFERENCE_IDENT" = T7."REFERENCE_IDENT") left outer join "deop01"."dbo"."ORDER_LINE" T6 on (T6."ORDER_NUMBER" = T7."ORDER_NUMBER") and (T6."LINE_NUMBER" = T7."ORDER_LINE_NUMBER"))
where (T1."ACCT_NR" = T2."ACCT_NO") and (T2."UNIQUE_IDENT" = T3."REFERENCE_IDENT")
and (((T1."TYPE_ACCTT" = '2') and (T1."ACCT_NR" LIKE '8%')) and ((T2."DEBIT_QUANTITY" + T2."CREDIT_QUANTITY") <> 0))

END SQL
COLUMN,0,Acct Nr_ori
COLUMN,1,Ledger Accts Name
COLUMN,2,Ledger Accts Name2
COLUMN,3,Handler
COLUMN,4,Dept Split
COLUMN,5,Type Acctt_ori
COLUMN,6,Acct No
COLUMN,7,Bookkeep Date
COLUMN,8,Bookkeep Period
COLUMN,9,Document No
COLUMN,10,Origin
COLUMN,11,Status
COLUMN,12,Debit Amount
COLUMN,13,Credit Amount
COLUMN,14,Debit Quantity
COLUMN,15,Credit Quantity
COLUMN,16,Aa Trtype
COLUMN,17,Department
COLUMN,18,Stock
COLUMN,19,Make Family
COLUMN,20,Make
COLUMN,21,Vehicle Type
COLUMN,22,Model Line
COLUMN,23,Factory Model
COLUMN,24,Workshop Model
COLUMN,25,Product Group
COLUMN,26,Repair Group
COLUMN,27,Kit Group
COLUMN,28,Time Code
COLUMN,29,Int Voucher No
COLUMN,30,Balancing Mark
COLUMN,31,Used Veh Dest Code
COLUMN,32,Use Of Vehicle
COLUMN,33,Acct No Next Chart
COLUMN,34,Reference Ident
COLUMN,35,Transact Date
COLUMN,36,Handler
COLUMN,37,Program
COLUMN,38,Function Code
COLUMN,39,Modul
COLUMN,40,Document Key
COLUMN,41,Comment
COLUMN,42,Department Type Id
COLUMN,43,Description
COLUMN,44,Department Group
COLUMN,45,Aa Trtype Id
COLUMN,46,Description
COLUMN,47,Own Description
COLUMN,48,Rechtseinheit
COLUMN,49,Betrieb
COLUMN,50,Marke
COLUMN,51,Mandant
COLUMN,52,Betrag
COLUMN,53,Text
COLUMN,54,Acct Nr
COLUMN,55,Susa
COLUMN,56,Order Number
COLUMN,57,Line Number
COLUMN,58,Inv Time
COLUMN,59,Inv Time Int
COLUMN,60,Make Time Unit
COLUMN,61,Type Acctt
COLUMN,62,EB

