Select with a CASE statement to a Apex Collection
MsMacJun 23 2010 — edited Jun 24 2010Attempting to use a case statement to determine the day of week from the LINEITEM_DATE2 field and then
placing the REG_HOURS into new columns in the collection representing the days of the week.
The case statement below(in bold) just is not working. I have even tried a simple when and hardcoding
a value. So can this be done this way?
I/P looks like this_________________
ATT_CODE REG_HOURS LINEITEM_DATE2
P 4 14-JUN-10
P 8 16-JUN-10
P 2 14-JUN-10
P2 8 15-JUN-10
O/P collection should look like this_________________ (slimmed down version)
ATT_CODE Monday Tuesday Wednesday
P 6 8
P2 8
declare
t_date date;
monday varchar(4) := '0';
begin
if htmldb_collection.collection_exists( 'TIMECOLLECTION') = FALSE
then htmldb_collection.create_collection( p_collection_name => 'TIMECOLLECTION' );
commit;
else
for c1 in (select collection_name, seq_id
from htmldb_collections
where collection_name = 'TIMECOLLECTION')
loop
htmldb_collection.delete_member(
p_collection_name => c1.collection_name,
p_seq => c1.seq_id);
commit;
end loop;
end if;
--t_date := to_date(:A_CURRENT_MONDAY_WEEK,'DD-MON-RR');
t_date := to_date('14-JUN-10', 'DD-MON-RR');
for rec in (select
ATT_CODE,
REG_HOURS,
LINEITEM_DATE2 as TRANSDATE,
CASE
WHEN to_date(LINEITEM_DATE2, 'DD_MON_RR') = to_date(t_date, 'DD_MON_RR')
THEN REG_HOURS
ELSE '0'
END as monday
from TRANSACTIONTIME
where :A_BADGE = BADGE
and LINEITEM_DATE2 >= t_date
and LINEITEM_DATE2 <= t_date+6)
loop
htmldb_collection.add_member(
p_collection_name => 'TIMECOLLECTION',
p_c001 => -1,
p_c003 => rec.TRANSDATE,
p_c004 => rec.ATT_CODE,
p_c005 => rec.CC,
p_c006 => rec.PC_ID,
p_c007 => rec.WO,
p_c008 => monday,
p_c009 => t_date+1,
p_c010 => t_date+2,
p_c011 => t_date+3,
p_c012 => t_date+4,
p_c013 => t_date+5,
p_c014 => t_date+6);
end loop;
END;