delete from direxame where codiex like 'A%';
delete from direxame where codiex like 'B%';
delete from direxame where codiex like 'C%';
delete from direxame where codiex like 'D%';
delete from direxame where codiex like 'E%';
delete from direxame where codiex like 'F%';
delete from direxame where codiex like 'G%';
delete from direxame where codiex like 'Z%';

delete from metaexas where metacodiex like 'A%';
delete from metaexas where metacodiex like 'B%';
delete from metaexas where metacodiex like 'C%';
delete from metaexas where metacodiex like 'D%';
delete from metaexas where metacodiex like 'E%';
delete from metaexas where metacodiex like 'F%';
delete from metaexas where metacodiex like 'G%';
delete from metaexas where metacodiex like 'Z%';



create table tempdirexame select * from direxame where u='1' and codiex like '0%';
update tempdirexame set u='M', convenio=1, codiex = concat('A',substr(codiex,2,3)), deducible = 0.00;
insert into direxame select * from tempdirexame;
update tempdirexame set u='M', convenio=1, codiex = concat('B',substr(codiex,2,3)), deducible = 0.00;
insert into direxame select * from tempdirexame;
update tempdirexame set u='M', convenio=1, codiex = concat('C',substr(codiex,2,3)), deducible = 0.00;
insert into direxame select * from tempdirexame;
update tempdirexame set u='M', convenio=1, codiex = concat('D',substr(codiex,2,3)), deducible = 0.00;
insert into direxame select * from tempdirexame;
update tempdirexame set u='M', convenio=1, codiex = concat('E',substr(codiex,2,3)), deducible = 0.00;
insert into direxame select * from tempdirexame;
update tempdirexame set u='M', convenio=1, codiex = concat('F',substr(codiex,2,3)), deducible = 0.00;
insert into direxame select * from tempdirexame;
update tempdirexame set u='M', convenio=1, codiex = concat('G',substr(codiex,2,3)), deducible = 0.00;
insert into direxame select * from tempdirexame;
update tempdirexame set u='M', convenio=1, codiex = concat('Z',substr(codiex,2,3)), deducible = 0.00;
insert into direxame select * from tempdirexame;
drop table tempdirexame;

create table tempmetaexas like metaexas;
insert into tempmetaexas (metacodiex, expandcode, precio, deducible, convenio) select codiex as metacodiex, concat('0',substr(codiex,2,3)) as expandcode, precio, (precio *0.20) as deducible, convenio from direxame where codiex like "A%";
insert into tempmetaexas (metacodiex, expandcode, precio, deducible, convenio) select codiex as metacodiex, concat('0',substr(codiex,2,3)) as expandcode, precio, (precio *0.25) as deducible, convenio from direxame where codiex like "B%";
insert into tempmetaexas (metacodiex, expandcode, precio, deducible, convenio) select codiex as metacodiex, concat('0',substr(codiex,2,3)) as expandcode, precio, (precio *0.30) as deducible, convenio from direxame where codiex like "C%";
insert into tempmetaexas (metacodiex, expandcode, precio, deducible, convenio) select codiex as metacodiex, concat('0',substr(codiex,2,3)) as expandcode, precio, (precio *0.35) as deducible, convenio from direxame where codiex like "D%";
insert into tempmetaexas (metacodiex, expandcode, precio, deducible, convenio) select codiex as metacodiex, concat('0',substr(codiex,2,3)) as expandcode, precio, (precio *0.40) as deducible, convenio from direxame where codiex like "E%";
insert into tempmetaexas (metacodiex, expandcode, precio, deducible, convenio) select codiex as metacodiex, concat('0',substr(codiex,2,3)) as expandcode, precio, (precio *0.45) as deducible, convenio from direxame where codiex like "F%";
insert into tempmetaexas (metacodiex, expandcode, precio, deducible, convenio) select codiex as metacodiex, concat('0',substr(codiex,2,3)) as expandcode, precio, (precio *0.50) as deducible, convenio from direxame where codiex like "G%";
insert into tempmetaexas (metacodiex, expandcode, precio, deducible, convenio) select codiex as metacodiex, concat('0',substr(codiex,2,3)) as expandcode, precio, (precio *0.00) as deducible, convenio from direxame where codiex like "Z%";

insert into metaexas (metacodiex, expandcode, precio,deducible, convenio) select metacodiex, expandcode, precio, deducible, convenio from tempmetaexas;
drop table tempmetaexas;
