Solved

INSERT INTO

Posted on 2004-10-13
2
337 Views
Last Modified: 2006-11-17
Hi Experts,

I have two tables A and B

A table has columns A1 A2
B table has              B1 B2

A1 is num from 1 to ~
B1 is num from 1 to ~

Let say I have in table A

1  MICHAEL
2  JOHN
3  JERRY

In table B I have

1 JEAN
2 ROY
3 SAM
4 GERALD

etc

I need to INSERT at the end of table A all rows from table B so that I have this result:

1  MICHAEL
2  JOHN
3  JERRY
4 JEAN
5 ROY
6 SAM
7 GERALD

Thank you.
0
Comment
Question by:fpoyavo
2 Comments
 
LVL 26

Accepted Solution

by:
Hilaire earned 500 total points
ID: 12299836
if the A1 is an auto-incremental identity field then you just need to

insert A(A2) select B2 from B

if it's not an identity field, you can do

insert A(A1, A2) select B1 + A1MAX,  B2
from B
cross join (select max(A1) as A1MAX from A) derived

0
 
LVL 15

Expert Comment

by:jdlambert1
ID: 12299845
INSERT TableA (NameColumn)
SELECT NameColumn
FROM TableB b
WHERE NOT EXISTS (SELECT NameColumn FROM TableA a WHERE a.NameColumn = b.NameColumn)
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

929 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now