sql server - how to copy data from one table to another table based on they have some same data in 3rd column? -
as question, how achieve goal? example table 1
place_id     place_name      invoice_no 100       sydney            null 101       melbourne         null 102       adlaide           null 103       gold coast        null 104       perth             null 105       hobart            null table 2
invoice_id   invoice_no       place_id 1        nit1001            100 2        nit1002            101 3        nit1002            102 4        nit1003            103 target table
place_id    place_name  invoice_no 100         sydney          nit1001         101        melbourne        nit1002         102        adlaide          nit1002         103        gold coast       nit1003         104        perth            null 105         hobart          null 
use join clause:
insert targettable select a.place_id, a.place_name, b.invoice_no table1 left join table2 b on a.place_id = b.place_id 
Comments
Post a Comment