Select us.CYCLE_CODE, us.CYCLE_RUN_MONTH, us.CYCLE_RUN_YEAR, us.BILL_SEQ_NO, us.BAN, us.Price_plan_code, soc.SOC_DESCRIPTION, us.Product_Type, us.at_charge_amt, at_call_dur_round_min, us.TOLL_DUR_ROUND_MIN, us.TOLL_CHARGE_AMT, att.ACC_TYPE, att.ACC_SUB_TYPE, att.DESCRIPTION
From Account_Type att, SOC, Billing_Account ba, US1907 us
Hi im new to sql but im trying to learn this is example database that need to run according to a specific month In code US1907
the code needs to be replace with the actual month 08 every time is runned .
also the first specific day are pre month example:
the actual numbers that don't update are in front set table DB_TABLE is already created inside database and so data is pooled from
US:
01 09
04 09
07 10
10 10
13 10
16 10
22 10
25 10
27 10
28 10
30 10
US0000 is changed for desired cycle and month. The first 2 digits are cycles they don't change unless DBA decides to and the other 2 for the month and pre month , the generated report start at the end of the previous month and ends almost at the end
Update: sorry i was diagnosed with covid and had to be hospitalized :
here is an update on the code i forgot to mention that's inserting data to a table :
INSERT INTO DB_TABLE
Select
'TABLE' AS "REPORT_CODE",
us.CYCLE_CODE,
DECODE(us.CYCLE_CODE, 1, DECODE(us.CYCLE_RUN_MONTH+1, 13, 1, us.CYCLE_RUN_MONTH+1), 4, DECODE(us.CYCLE_RUN_MONTH+1, 13, 1, us.CYCLE_RUN_MONTH+1), us.CYCLE_RUN_MONTH) AS "CYCLE_RUN_MONTH",
DECODE(us.CYCLE_CODE, 1, DECODE(us.CYCLE_RUN_MONTH, 12, us.CYCLE_RUN_YEAR+1, us.CYCLE_RUN_YEAR), 4, DECODE(us.CYCLE_RUN_MONTH, 12, us.CYCLE_RUN_YEAR+1, us.CYCLE_RUN_YEAR), us.CYCLE_RUN_YEAR) AS "CYCLE_RUN_YEAR",
us.BILL_SEQ_NO,
us.BAN,
us.Price_plan_code,
us.SOC_DESCRIPTION,
us.Product_Type,
--Ciclo, BAN, Price_plan_code, SOC_DESCRIPTION, Product_Type,
(CASE ACC_TYPE
WHEN 'I' THEN 'Consummer'
WHEN 'B' THEN 'Buisness'
WHEN 'G' THEN 'Work'
ELSE 'None'
END) AS ACC_TYPE,
ACC_SUB_TYPE,
DESCRIPTION,
Sum(Decode(us.at_charge_amt,Null,0,us.at_call_dur_round_min)) "Billed",
(Sum(us.at_call_dur_round_min) - Sum(Decode(us.at_charge_amt,Null,0,us.at_call_dur_round_min))) "free minutes",
Sum(us.at_call_dur_round_min) "TOTAL",
Sum(us.at_charge_amt) "CHARGES"
From
(
Select us.CYCLE_CODE, us.CYCLE_RUN_MONTH, us.CYCLE_RUN_YEAR, us.BILL_SEQ_NO, us.BAN, us.Price_plan_code, soc.SOC_DESCRIPTION, us.Product_Type, us.at_charge_amt, at_call_dur_round_min, us.TOLL_DUR_ROUND_MIN, us.TOLL_CHARGE_AMT, att.ACC_TYPE, att.ACC_SUB_TYPE, att.DESCRIPTION
From Account_Type att, SOC, Billing_Account ba, US0000 us
Where
ba.BAN = us.BAN
And ba.ACCOUNT_TYPE = att.ACC_TYPE
And ba.ACCOUNT_SUB_TYPE = att.ACC_SUB_TYPE
And us.Price_plan_code = soc.SOC
And soc.EXPIRATION_DATE Is Null
And us.Product_Type = 'F'
And us.Call_Action_Code = 2
And us.Cancel_Record_Ind = 'N'
And Trim(us.AT_FEATURE_CODE) = 'STD14'
) us
Where
(trim(us.acc_type)||trim(us.acc_sub_type)) Not In ('BZ','Bt','BT')
Group By
us.CYCLE_CODE, us.CYCLE_RUN_MONTH, us.CYCLE_RUN_YEAR, us.BILL_SEQ_NO, us.BAN, us.Price_plan_code, us.SOC_DESCRIPTION, us.Product_Type, ACC_TYPE, ACC_SUB_TYPE, DESCRIPTION;
COMMIT;