Sunday, March 11, 2012

Bulk Insert from a table to Another

Hi guys,

Consider this Scenario.

I have two Tables.

Table1-Users

Fields are

id, name,joindate,designation, status

Table2-People

Fields are

id, name, status

The table Users have data in it say 100 records

I have to fill it toPeople Table where id=id and name=name and status=status

Any Way?

Regards,

Naveen

If it's an insert action, why do you need to match the row values?

For a simple insert, you can do:

INSERT INTO [people](id,name, status)SELECT id,name, status-- assumed id is PKFROM [users]WHERE idNOT IN (SELECT idFROM people)-- make sure you don't insert duplicate ID

No comments:

Post a Comment