It's not reading CASE in GROUP BY! Can anyone explain what is wrong?
This script works only if I delet SUM and GROUP BY or if i delet CASE statment from GROUP BY than it works too (but than it freezes after 100 records, i think because it hits SO transactions)
Thank-you!!!!
SELECT b.en_ent
,e.sa_sub
,c.cc_cstctr
,d.acct_acc
,b. en_entity_lng
,e. sa_sub_lng
,c. cost_ctr_lng
,d. acct_acc_lng
,f. fiscal_month
,f. fiscal_year_lng
,d. acct_type
,a. gl_tr_type
,CASE
WHEN a.gl_tr_type = 'SO' THEN
(SELECT g. cust_name
FROM F_ACCT_TRX_HIST_STG2 a
,finmart.D_CUSTOMER g
,dssmart.f_sales_invoice h
WHERE a.gl_doc = h.inv_nbr
AND h.inv_cust_bill_to_nbr = g.cust_nbr)
ELSE
NULL
END cust_name
,SUM(a.gl_amt)
FROM F_ACCT_TRX_HIST_STG2 a
,D_ENTITY_STG2 b
,D_COSTCTR_STG2 c
,D_ACCTS_STG2 d
,D_SUBACCTS_STG2 e
,D_PERIOD_STG1 f
WHERE a.gl_ent = b.en_ent
AND c.cc_cstctr = UPPER(a.gl_cc)
AND d.acct_acc = a.gl_acc
AND e.sa_sub = a.gl_sa
AND a.gl_eff_dt = f.calendar_date
GROUP BY b.en_ent
,e.sa_sub
,c.cc_cstctr
,d.acct_acc
,b. en_entity_lng
,e. sa_sub_lng
,c. cost_ctr_lng
,d. acct_acc_lng
, CASE
WHEN a.gl_tr_type = 'SO' THEN
(SELECT g. cust_name
FROM F_ACCT_TRX_HIST_STG2 a
,finmart.D_CUSTOMER g
,dssmart.f_sales_invoice h
WHERE a.gl_doc = h.inv_nbr
AND h.inv_cust_bill_to_nbr = g.cust_nbr)
ELSE
NULL
END
,f. fiscal_month
,f. fiscal_year_lng
,d. acct_type
,a. gl_tr_type
This script works only if I delet SUM and GROUP BY or if i delet CASE statment from GROUP BY than it works too (but than it freezes after 100 records, i think because it hits SO transactions)
Thank-you!!!!
SELECT b.en_ent
,e.sa_sub
,c.cc_cstctr
,d.acct_acc
,b. en_entity_lng
,e. sa_sub_lng
,c. cost_ctr_lng
,d. acct_acc_lng
,f. fiscal_month
,f. fiscal_year_lng
,d. acct_type
,a. gl_tr_type
,CASE
WHEN a.gl_tr_type = 'SO' THEN
(SELECT g. cust_name
FROM F_ACCT_TRX_HIST_STG2 a
,finmart.D_CUSTOMER g
,dssmart.f_sales_invoice h
WHERE a.gl_doc = h.inv_nbr
AND h.inv_cust_bill_to_nbr = g.cust_nbr)
ELSE
NULL
END cust_name
,SUM(a.gl_amt)
FROM F_ACCT_TRX_HIST_STG2 a
,D_ENTITY_STG2 b
,D_COSTCTR_STG2 c
,D_ACCTS_STG2 d
,D_SUBACCTS_STG2 e
,D_PERIOD_STG1 f
WHERE a.gl_ent = b.en_ent
AND c.cc_cstctr = UPPER(a.gl_cc)
AND d.acct_acc = a.gl_acc
AND e.sa_sub = a.gl_sa
AND a.gl_eff_dt = f.calendar_date
GROUP BY b.en_ent
,e.sa_sub
,c.cc_cstctr
,d.acct_acc
,b. en_entity_lng
,e. sa_sub_lng
,c. cost_ctr_lng
,d. acct_acc_lng
, CASE
WHEN a.gl_tr_type = 'SO' THEN
(SELECT g. cust_name
FROM F_ACCT_TRX_HIST_STG2 a
,finmart.D_CUSTOMER g
,dssmart.f_sales_invoice h
WHERE a.gl_doc = h.inv_nbr
AND h.inv_cust_bill_to_nbr = g.cust_nbr)
ELSE
NULL
END
,f. fiscal_month
,f. fiscal_year_lng
,d. acct_type
,a. gl_tr_type