TRUNCATE ventas;
LOAD DATA INFILE 'C:\\files\\espacios.txt' INTO TABLE ventas FIELDS TERMINATED BY '|' ENCLOSED BY '@' ESCAPED BY '' LINES TERMINATED BY '\n'  IGNORE 1 LINES(
 @col1
 ) set   
 EMPVTA=TRIM(SUBSTRING(@col1,1,63)),
 DIAVTA=TRIM(SUBSTRING(@col1,63,2)),
 MESVTA=TRIM(SUBSTRING(@col1,65,4)),
 ANOVTA=TRIM(SUBSTRING(@col1,69,6)),
 NDIVTA=TRIM(SUBSTRING(@col1,75,24)),
 HORVTA=TRIM(SUBSTRING(@col1,97,2)),
 PZAVTA=TRIM(SUBSTRING(@col1,99,13)),   /* FILTRO DE PIEZAS */
 UMPVTA=TRIM(SUBSTRING(@col1,112,11)),
 CUNVTA=TRIM(SUBSTRING(@col1,123,16)),
 CEMVTA=TRIM(SUBSTRING(@col1,139,13)), /* CAJAS / DE EMPAQUE EN PIEZAS */
 UEMVTA=TRIM(SUBSTRING(@col1,152,20)),
 PRDVTA=TRIM(SUBSTRING(@col1,172,40)),
 MTUVTA=TRIM(SUBSTRING(@col1,212,37)), /* MONTO UNITARIO DE VENTA (P.UNITARIO)*/
 MTTVTA=TRIM(SUBSTRING(@col1,249,17)), /* MONTO TOTAL DE VENTA  (CEMVTA X MTUVTA) */ 
 COLVTA=TRIM(SUBSTRING(@col1,266,17)),
 MUNVTA=TRIM(SUBSTRING(@col1,306,40)), 
 CIUVTA=TRIM(SUBSTRING(@col1,346,40)), /* FILTRO CIUDAD */
 TIPVTA=TRIM(SUBSTRING(@col1,386,40)),
 CANVTA=TRIM(SUBSTRING(@col1,426,40)), /* FILTRO CANAL */
 ETDVTA=TRIM(SUBSTRING(@col1,466,13)), /* EXISTENCIA EN TIENDA */
 ETOVTA=TRIM(SUBSTRING(@col1,479,13)), /* EXISTENCIA TOTAL */
 PRVVTA=TRIM(SUBSTRING(@col1,492,13)),
 CVEVTA=TRIM(SUBSTRING(@col1,532,10)), 
 REFVTA=TRIM(SUBSTRING(@col1,542,10)),
 CVCVTA=TRIM(SUBSTRING(@col1,552,10)),
 NOCVTA=TRIM(SUBSTRING(@col1,562,40)),
 RFCVTA=TRIM(SUBSTRING(@col1,602,40)),
 PRMVTA=TRIM(SUBSTRING(@col1,642,35)),
 NLTVTA=TRIM(SUBSTRING(@col1,677,13)), /* NÚMERO DE CAJAS 9LT - CUERVO */ 
 CL1VTA=TRIM(SUBSTRING(@col1,690,50)), /* FILTRO SEGMENTO */ 
 CL2VTA=TRIM(SUBSTRING(@col1,740,50)), /* ?????  */ 
/* FECHA=date_format(str_to_date(TRIM(SUBSTRING(@col1,1240,10)), '%m/%d/%Y'), '%Y-%m-%d'), */
 FECHA=date_format(str_to_date(CONCAT(ANOVTA,'-',MESVTA,'-',DIAVTA), '%Y-%m-%d'), '%Y-%m-%d'), 
 STATUS=TRIM(SUBSTRING(@col1,1250,1)),
 SERIE=TRIM(SUBSTRING(@col1,1251,3)), 
 FOLIO=TRIM(SUBSTRING(@col1,1254,8)), 
 DOCUME=TRIM(SUBSTRING(@col1,1262,25)), 
 UUID=TRIM(SUBSTRING(@col1,1287,40)),
 SUCURS=TRIM(SUBSTRING(@col1,1327,40)), /*FILTRO SUCURSAL*/
 COSTO=TRIM(SUBSTRING(@col1,1367,17)),
 UTILID=TRIM(SUBSTRING(@col1,1384,17)), 
 CVPVTA=TRIM(SUBSTRING(@col1,1401,10)), 
 COPVTA=TRIM(SUBSTRING(@col1,1411,20)), 
 ITRVTA=TRIM(SUBSTRING(@col1,1431,10)), 
 created_at=NOW(); 

