Ver Mensaje Individual
  #3 (permalink)  
Antiguo 27/11/2013, 09:18
agamc1993
 
Fecha de Ingreso: mayo-2013
Mensajes: 19
Antigüedad: 11 años
Puntos: 0
Respuesta: INSERT SELECT salta valores!

No los inserta, deberían ser al rededor de 216,000 registros solo para el query de ejemplo, pero inserta solo 60,000 :/

perdón, me confundí de PHP, es el siguiente

Código PHP:
$query1="SELECT
            unidades.id,
            unidades.codigo,
            unidades.nombre,
            unidades.tipo 
        FROM
            unidades
        WHERE
            unidades.codigo != 'MANAGER'
        AND
            unidades.codigo != ''
        AND 
            unidades.activo = '1'
        ORDER BY
            unidades.id ASC"
;
$sql1=mysql_query($query1);
while(
$row1=mysql_fetch_row($sql1))
    {
        if(
$row1[3]=="PLANTA")
        {
            
$store=$row1[2];
        }else
        {
            
$selectsucursal="SELECT
                relaciones_uniones.id_relacion,
                relaciones.id_planta,
                unidades.nombre as nombre
            FROM
                relaciones_uniones
            Inner Join relaciones on relaciones.id=relaciones_uniones.id_relacion
            Inner Join unidades on relaciones.id_planta=unidades.id
            WHERE
                relaciones_uniones.id_sucursal='"
.$row1[0]."'
            ORDER BY
                relaciones.fecha DESC"
;
            
$sqlsucursal=mysql_query($selectsucursal);
            while(
$rowntea=mysql_fetch_row($sqlsucursal))
            {
                
$store=$rowntea[2];
                break;
            }
        }
        
mysql_free_result($sqlsucursal);
        
        
set_time_limit(3600);
        
        
        
$query2="INSERT INTO
                    kpi
                    (ciudad, planta, sucursal, canal, orden, ticket, tipo_orden, fecha_elaboracion, fecha_promesa, fecha_finalizacion, fecha_entrega, lote, tiempo_de_ciclo, usuario, cliente, direccion, colonia, municipio, cp, telefono, creditos, alta, total_prendas, tipo, descripcion, cantidad, color, precio_unitario, importe, subtotal, credito_usado, descuento, efectivo, estatus_transaccion, cambio, total, estatus)
                SELECT 
                    'Guadalajara',
                    '"
.$store."',
                    '"
.$row1[2]."',
                    '"
.$row1[3]."',
                    "
.strtolower($row1[1])."_prendas_tickets.id_orden as orden,
                    "
.strtolower($row1[1])."_prendas_tickets.id_ticket as ticket,
                    'Venta',
                    "
.strtolower($row1[1])."_tickets.fecha_aper as fecha_elaboracion,
                    "
.strtolower($row1[1])."_tickets.fecha_promesa as fecha_promesa,
                    "
.strtolower($row1[1])."_tickets.fecha_asignacion as fecha_finalizacion,
                    "
.strtolower($row1[1])."_tickets.fecha_entrega as fecha_entrega,
                    "
.strtolower($row1[1])."_tickets.id_lote as lote,
                    ((lotes.hora_final)-(lotes.hora_inicio)) as tiempo_de_ciclo,
                    "
.strtolower($row1[1])."_ordenes.atendio as usuario,
                    "
.strtolower($row1[1])."_ordenes.nombre as cliente,
                    clientes.direccion as direccion,
                    clientes.colonia as colonia,
                    clientes.ciudad as municipio,
                    clientes.cp as cp,
                    "
.strtolower($row1[1])."_ordenes.telefono as telefono,
                    clientes.credito as creditos,
                    clientes.fecha as alta,
                    clientes.prendas as total_prendas,
                    'Prenda',
                    "
.strtolower($row1[1])."_prendas_tickets.prenda as descripcion,
                    "
.strtolower($row1[1])."_prendas_tickets.cant as cantidad,
                    "
.strtolower($row1[1])."_prendas_tickets.color as color,
                    "
.strtolower($row1[1])."_prendas_tickets.precio_unitario as precio_unitario,
                    "
.strtolower($row1[1])."_prendas_tickets.importe as importe,
                    "
.strtolower($row1[1])."_ordenes.subtotal as subtotal,
                    "
.strtolower($row1[1])."_ordenes.credito as credito_usado,
                    "
.strtolower($row1[1])."_ordenes.frecuente as descuento,
                    "
.strtolower($row1[1])."_ordenes.pago as efectivo,
                    "
.strtolower($row1[1])."_ordenes.corte as estatus_transaccion,
                    "
.strtolower($row1[1])."_ordenes.cambio as cambio,
                    "
.strtolower($row1[1])."_ordenes.total as total,
                    "
.strtolower($row1[1])."_tickets.estatus as estatus
                FROM
                    "
.strtolower($row1[1])."_prendas_tickets
                Inner Join "
.strtolower($row1[1])."_tickets on ".strtolower($row1[1])."_tickets.id=".strtolower($row1[1])."_prendas_tickets.id_ticket
                Inner Join "
.strtolower($row1[1])."_ordenes on ".strtolower($row1[1])."_ordenes.id=".strtolower($row1[1])."_prendas_tickets.id_orden
                Inner Join clientes on clientes.telefono="
.strtolower($row1[1])."_ordenes.telefono
                Inner Join lotes on lotes.id="
.strtolower($row1[1])."_tickets.id_lote
                WHERE
                    "
.strtolower($row1[1])."_tickets.fecha_aper>'2012-01-01'
                    AND
                    "
.strtolower($row1[1])."_tickets.fecha_aper<'2013-11-12'
                ORDER BY
                    "
.strtolower($row1[1])."_tickets.fecha_aper ASC
                    "
;
                    
$resultado=mysql_query($query2);
            
            echo 
$row1[2]." ".mysql_affected_rows()."<br/>";
    }
echo 
mysql_error();