locked
TRASLADO DE DATOS DE UNA TABLA A OTRA SQL 2008 RRS feed

  • Question

  • Buenas noches..

    Les parecera algo raro pero espero me puedan entender y comprender..
    Estoy haciendo un pequeño aplicativo para una tienda de un amigo..
    El posee dos negocios no muy lejano uno del otro..

    El problema radica en que por la accesibilidad de la zona le es muy
    dificil conseguir un proveedor de internet por lo que me es un poco dificil
    concentrar la data en un solo punto..

    En ambos negocios tienen la misma BD.. en una tabla registro la venta
    de los productos.. Lo que yo quiero es trasladar los datos de esas dos tablas
    a una tabla vacia..

    Como puedo trasladar la data de ambas BD.. dejando de lado la data que ya pase.. x ejemplo..

    El lunes lo que vendi es..
    Prod. A, B, C y D..

    EL martes vendi.. E y F..
    por lo que mi tabla estaria con los datos A, B, C, D, E y F..

    Lo que no quiero es sobreescribir la info que ya esta..

    Deseo saber si existe alguna manera de pasar los datos que no estan en la bd.. 
    Muchas gracias..


    Jokesito

    Tuesday, March 12, 2013 5:16 AM

Answers

  • Hello,

    I would translate your question to English using Bing Translator:
    Good night..

    You seem rather rare but I hope I can understand and comprehend...

    I'm doing a small application for a shop of a friend...

    He owns two businesses not-too-distant one from the other...

    The problem is that by the accessibility of the area is very

    difficult to get an ISP so me is a little difficult

    focus the data at a single point...

    Both businesses have the same BD... in a table log sale

    products... What I want is to transfer the data from these two tables

    to an empty table...

    How can I transfer the data of both BD... aside from the data that already happens... x example...

    On Monday which is sold...

    Prod. A, B, C and D..

    ON Tuesday sold... E and F...

    so my table would be with the data A, B, C, D, E and F...

    What I don't want is overwrite the info that this...

    I want to know if there is any way to pass data that are not in the database...

    Thanks a lot..

    ------------------------------------------------------------------------------------
    My suggestion is to use the Merge statement with “WHEN NOT MATCHED”. For more information:

    http://msdn.microsoft.com/en-us/library/bb510625.aspx

    You can use EXISTS …

    INSERT INTO TABLE_2

      (id, name)

    SELECT t1.id,

           t1.name

      FROM TABLE_1 t1

     WHERE NOT EXISTS(SELECT id

                        FROM TABLE_2 t2

                       WHERE t2.id = t1.id

    And you can use NOT IN …

    INSERT INTO TABLE_2

      (id, name)

    SELECT t1.id,

           t1.name

      FROM TABLE_1 t1

     WHERE t1.id NOT IN (SELECT id

                           FROM TABLE_2)

    If you would like to receive help in Spanish, please visit the following forum:

    http://social.technet.microsoft.com/Forums/es-ES/sqlserveres/threads

    Hope this helps.

    Regards,

    Alberto Morillo
    SQLCoffee.com

    • Marked as answer by Jokesito Wednesday, March 13, 2013 3:27 AM
    Tuesday, March 12, 2013 1:19 PM