insert into metadata_statistics(rundate, metadata_defn, order_sequence, total_entries, metadata_id) 
select to_date(sysdate,'YYYY-MM-DD-HH24:MI:SS'), 'DataSizePerCategory', rownum, totals, id from 
(select cab_category_id as id, 
sum(length(coalesce(cab_value_numeric,1))+
length(coalesce(cab_value_string,'N'))+
coalesce(length(cab_value_date),1)) as totals
from cab 
where  cab_company_id = 40001
and cab_next_version_id = 999999999
group by cab_category_id
order by totals desc
) ;
commit;
quit;
