insert into metadata_statistics (order_sequence, metadata_defn, total_entries, rundate, metadata_id)
select rownumber() over(order by data_size desc), 
'DataSizePerCategory', data_size, current timestamp, id 
from (
select cad_category_id as id, 
coalesce(length(cad_blob),length(cad_bit_varchar),1) as data_size
from cad
where  cad_company_id = 40001
and cad_next_version_id = 999999999
) as temp
;
commit;
