select c.usuario_cic, dia, b.jornada, b.manana, b.colacion, b.tarde, case length(jornada) WHEN 11 then mid(jornada,1,5) else mid(manana,1,5) END as inicio, case length(jornada) WHEN 11 then mid(jornada,7,5) else mid(tarde,7,5) END as fin, ifnull(a.permiso,'0') as permiso, a.turno, round(( mod(b.t0000,2)+ mod(b.t0015,2)+ mod(b.t0030,2)+ mod(b.t0045,2)+ mod(b.t0100,2)+ mod(b.t0115,2)+ mod(b.t0130,2)+ mod(b.t0145,2)+ mod(b.t0200,2)+ mod(b.t0215,2)+ mod(b.t0230,2)+ mod(b.t0245,2)+ mod(b.t0300,2)+ mod(b.t0315,2)+ mod(b.t0330,2)+ mod(b.t0345,2)+ mod(b.t0400,2)+ mod(b.t0415,2)+ mod(b.t0430,2)+ mod(b.t0445,2)+ mod(b.t0500,2)+ mod(b.t0515,2)+ mod(b.t0530,2)+ mod(b.t0545,2)+ mod(b.t0600,2)+ mod(b.t0615,2)+ mod(b.t0630,2)+ mod(b.t0645,2)+ mod(b.t0700,2)+ mod(b.t0715,2)+ mod(b.t0730,2)+ mod(b.t0745,2)+ mod(b.t0800,2)+ mod(b.t0815,2)+ mod(b.t0830,2)+ mod(b.t0845,2)+ mod(b.t0900,2)+ mod(b.t0915,2)+ mod(b.t0930,2)+ mod(b.t0945,2)+ mod(b.t1000,2)+ mod(b.t1015,2)+ mod(b.t1030,2)+ mod(b.t1045,2)+ mod(b.t1100,2)+ mod(b.t1115,2)+ mod(b.t1130,2)+ mod(b.t1145,2)+ mod(b.t1200,2)+ mod(b.t1215,2)+ mod(b.t1230,2)+ mod(b.t1245,2)+ mod(b.t1300,2)+ mod(b.t1315,2)+ mod(b.t1330,2)+ mod(b.t1345,2)+ mod(b.t1400,2)+ mod(b.t1415,2)+ mod(b.t1430,2)+ mod(b.t1445,2)+ mod(b.t1500,2)+ mod(b.t1515,2)+ mod(b.t1530,2)+ mod(b.t1545,2)+ mod(b.t1600,2)+ mod(b.t1615,2)+ mod(b.t1630,2)+ mod(b.t1645,2)+ mod(b.t1700,2)+ mod(b.t1715,2)+ mod(b.t1730,2)+ mod(b.t1745,2)+ mod(b.t1800,2)+ mod(b.t1815,2)+ mod(b.t1830,2)+ mod(b.t1845,2)+ mod(b.t1900,2)+ mod(b.t1915,2)+ mod(b.t1930,2)+ mod(b.t1945,2)+ mod(b.t2000,2)+ mod(b.t2015,2)+ mod(b.t2030,2)+ mod(b.t2045,2)+ mod(b.t2100,2)+ mod(b.t2115,2)+ mod(b.t2130,2)+ mod(b.t2145,2)+ mod(b.t2200,2)+ mod(b.t2215,2)+ mod(b.t2230,2)+ mod(b.t2245,2)+ mod(b.t2300,2)+ mod(b.t2315,2)+ mod(b.t2330,2)+ mod(b.t2345,2) ) as suma from turno_diario_real a, def_turnos b, ejecutivos c where a.usuario=c.usuario and a.turno=b.turno and a.dia>='20190901' and a.dia<='20190908' and a.usuario='FMORALES' order by a.dia asc