Solved

INSERT INTO

Posted on 2004-10-13
2
354 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.

809 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