<?php

$campo1 = "autoin";
$campo2 = "op_fechae";
$campo3 = "id_tipo";
$campo4 = "op_id";
$campo5 = "c_id";
$campo6 = "cxc_detalle";
$campo7 = "op_fechav";
$campo8 = "op_debito";
$campo9 = "op_credito";
$campo10 = "op_saldo";
$campo11 = "op_abono";
$campo12 = "op_canc";
$campo13 = "op_apagar";
$campo14 = "op_estado";
$campo15 = "op_tipodoc";
$campo16 = "u_id";
$campo17 = "op_sec_id";
$campo18 = "activado";
$campo19 = "autoinc_banco";
$campo20 = "op_neto";
$campo21 = "suc_id";
$campo22 = "conc_id";
$campo23 = "op_signo";
$campo24 = "op_fechac";
$campo25 = "op_contab";
$campo26 = "op_base";
$campo27 = "op_itbms";
$campo28 = "pers_id";
$campo29 = "op_orig";
$campo30 = "op_rel";
$campo31 = "op_num_doc";
$campo32 = "op_num_fact";
$campo33 = "op_fecha_capt";
$campo34 = "op_num_docfis";
$campo35 = "op_recarg";
$campo36 = "mon_op";
$campo37 = "mon_taza_op";
$campo38 = "op_retenc";
$campo39 = "id_retenc";
$campo40 = "mon_id1";
$campo41 = "mon_taza_v1";
$campo42 = "mon_taza_c1";
$campo43 = "mon_id2";
$campo44 = "mon_taza_v2";
$campo45 = "mon_taza_c2";
$campo46 = "mon_id3";
$campo47 = "mon_taza_v3";
$campo48 = "mon_taza_c3";
$campo49 = "op_info";
$campo50 = "op_aptdo";
$campo51 = "op_visible";
$campo52 = "syncprocesing";
$campo53 = "usermodify";
$campo54 = "useroption";

$valor = $campo1 . "," .
    $campo2 . "," .
    $campo3 . "," .
    $campo4 . "," .
    $campo5 . "," .
    $campo6 . "," .
    $campo7 . "," .
    $campo8 . "," .
    $campo9 . "," .
    $campo10 . "," .
    $campo11 . "," .
    $campo12 . "," .
    $campo13 . "," .
    $campo14 . "," .
    $campo15 . "," .
    $campo16 . "," .
    $campo17 . "," .
    $campo18 . "," .
    $campo19 . "," .
    $campo20 . "," .
    $campo21 . "," .
    $campo22 . "," .
    $campo23 . "," .
    $campo24 . "," .
    $campo25 . "," .
    $campo26 . "," .
    $campo27 . "," .
    $campo28 . "," .
    $campo29 . "," .
    $campo30 . "," .
    $campo31 . "," .
    $campo32 . "," .
    $campo33 . "," .
    $campo34 . "," .
    $campo35 . "," .
    $campo36 . "," .
    $campo37 . "," .
    $campo38 . "," .
    $campo39 . "," .
    $campo40 . "," .
    $campo41 . "," .
    $campo42 . "," .
    $campo43 . "," .
    $campo44 . "," .
    $campo45 . "," .
    $campo46 . "," .
    $campo47 . "," .
    $campo48 . "," .
    $campo49 . "," .
    $campo50 . "," .
    $campo51 . "," .
    $campo52 . "," .
    $campo53 . "," .
    $campo54;

$db_destino = $database;
$tabla_dest = "operacion_cxc";
$db_tmp = "tmp";

$llave = "autoin";

$sqlop1 = "update  " . $db_destino . "." . $tabla_dest . ",  " . $db_tmp . "." . $_SESSION['unico'] . " b " . " set "

    . $tabla_dest . "." . $campo2 . "=b." . $campo2 . ",  "
    . $tabla_dest . "." . $campo3 . "=b." . $campo3 . ",  "
    . $tabla_dest . "." . $campo4 . "=b." . $campo4 . ",  "
    . $tabla_dest . "." . $campo5 . "=b." . $campo5 . ",  "
    . $tabla_dest . "." . $campo6 . "=b." . $campo6 . ",  "
    . $tabla_dest . "." . $campo7 . "=b." . $campo7 . ",  "
    . $tabla_dest . "." . $campo8 . "=b." . $campo8 . ",  "
    . $tabla_dest . "." . $campo9 . "=b." . $campo9 . ",  "
    . $tabla_dest . "." . $campo10 . "=b." . $campo10 . ",  "
    . $tabla_dest . "." . $campo11 . "=b." . $campo11 . ",  "
    . $tabla_dest . "." . $campo12 . "=b." . $campo12 . ",  "
    . $tabla_dest . "." . $campo13 . "=b." . $campo13 . ",  "
    . $tabla_dest . "." . $campo14 . "=b." . $campo14 . ",  "
    . $tabla_dest . "." . $campo15 . "=b." . $campo15 . ",  "
    . $tabla_dest . "." . $campo16 . "=b." . $campo16 . ",  "
    . $tabla_dest . "." . $campo17 . "=b." . $campo17 . ",  "
    . $tabla_dest . "." . $campo18 . "=b." . $campo18 . ",  "
    . $tabla_dest . "." . $campo19 . "=b." . $campo19 . ",  "
    . $tabla_dest . "." . $campo20 . "=b." . $campo20 . ",  "
    . $tabla_dest . "." . $campo21 . "=b." . $campo21 . ",  "
    . $tabla_dest . "." . $campo22 . "=b." . $campo22 . ",  "
    . $tabla_dest . "." . $campo23 . "=b." . $campo23 . ",  "
    . $tabla_dest . "." . $campo24 . "=b." . $campo24 . ",  "
    . $tabla_dest . "." . $campo25 . "=b." . $campo25 . ",  "
    . $tabla_dest . "." . $campo26 . "=b." . $campo26 . ",  "
    . $tabla_dest . "." . $campo27 . "=b." . $campo27 . " ,"

    . $tabla_dest . "." . $campo28 . "=b." . $campo28 . ",  "
    . $tabla_dest . "." . $campo29 . "=b." . $campo29 . ",  "
    . $tabla_dest . "." . $campo30 . "=b." . $campo30 . ",  "
    . $tabla_dest . "." . $campo31 . "=b." . $campo31 . ",  "
    . $tabla_dest . "." . $campo32 . "=b." . $campo32 . ",  "
    . $tabla_dest . "." . $campo33 . "=b." . $campo33 . ",  "
    . $tabla_dest . "." . $campo34 . "=b." . $campo34 . ",  "
    . $tabla_dest . "." . $campo35 . "=b." . $campo35 . ",  "
    . $tabla_dest . "." . $campo36 . "=b." . $campo36 . ",  "
    . $tabla_dest . "." . $campo37 . "=b." . $campo37 . ",  "
    . $tabla_dest . "." . $campo38 . "=b." . $campo38 . ",  "
    . $tabla_dest . "." . $campo39 . "=b." . $campo39 . ",  "
    . $tabla_dest . "." . $campo40 . "=b." . $campo40 . ",  "
    . $tabla_dest . "." . $campo41 . "=b." . $campo41 . ",  "
    . $tabla_dest . "." . $campo42 . "=b." . $campo42 . ",  "
    . $tabla_dest . "." . $campo43 . "=b." . $campo43 . ",  "
    . $tabla_dest . "." . $campo44 . "=b." . $campo44 . ",  "
    . $tabla_dest . "." . $campo45 . "=b." . $campo45 . ",  "
    . $tabla_dest . "." . $campo46 . "=b." . $campo46 . ",  "
    . $tabla_dest . "." . $campo47 . "=b." . $campo47 . ",  "
    . $tabla_dest . "." . $campo48 . "=b." . $campo48 . ",  "
    . $tabla_dest . "." . $campo49 . "=b." . $campo49 . ",  "
    . $tabla_dest . "." . $campo50 . "=b." . $campo50 . ",  "
    . $tabla_dest . "." . $campo51 . "=b." . $campo51 . ",  "
    . $tabla_dest . "." . $campo52 . "=b." . $campo52 . ",  "
    . $tabla_dest . "." . $campo53 . "=b." . $campo53 . ",  "
    . $tabla_dest . "." . $campo54 . "=b." . $campo54 .

    " where "
    . $tabla_dest . "." . $llave . "=b." . $llave;

$sqlop2 = "insert into " . $db_destino . "." . $tabla_dest . " ( "
    . $valor . ") select " . $valor . " from " . $db_tmp . "."
    . $_SESSION['unico'] . "  where " . $llave . " not in (select " . $llave
    . " from " . $db_destino . "." . $tabla_dest . " " . " where "
    . $llave . " is not null)    group by " . $llave;

?>