2

I have tableA, tableB and tableC like the image. TableC assumption is empty. How to insert data into tableC with Insert Into Select statement ?

Data tableC from tableB with contition from tableA.

I can do it with cursor.

enter image description here

Liudi Wijaya
  • 898
  • 2
  • 8
  • 24

2 Answers2

1

When possible, you should try to avoid using cursors for these types of inserts :) (think in sets)

Here is 1 way how to do it:

insert
into TableC(ColA, ColB, ColC)
select a.ColA, a.ColB, a.ColC
from TableA a
join TableB b on b.ColA = a.ColA and b.ColB = a.ColB
dana
  • 17,267
  • 6
  • 64
  • 88
0

Please try below query.

    insert into tablec(cola , colb , colc ) 
    select b.cola, b.colb, a.colc from tableb b, tablea a 
    where a.cola = b.cola and a.colb = b.colb;
Mahesh.K
  • 901
  • 6
  • 15
Akshay
  • 11
  • 2