?
Solved

How to write a SQL Server statement to insert records into 1 table from another using SQL Server 2005?

Posted on 2011-09-02
3
Medium Priority
?
223 Views
Last Modified: 2012-05-12
I am working with SQL Server 2005.
I have 2 SQL Server tables named tblNew and tblCum.
These tables have identical data structures and field names.
The first field in the tables is named MailID and is unique.
How would you write a SQL Server statement to insert records into table tblCum from table
tblNew where MailID in tblNew is not in table tblCum?
 
0
Comment
Question by:zimmer9
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 13

Accepted Solution

by:
LIONKING earned 1000 total points
ID: 36473991
INSERT INTO tblCum
SELECT * FROM tblNew WHERE tblNew.MailID NOT IN (SELECT a.MailID FROM tblCum a)
0
 
LVL 57

Expert Comment

by:HainKurt
ID: 36473994
try:

insert into tblCum
(select * from tblNew n where not exists (select 1 from tblCum c where c.mailid=n.mailid))
0
 
LVL 57

Assisted Solution

by:HainKurt
HainKurt earned 1000 total points
ID: 36474007
oops, (..) not needed


insert into tblCum
select * from tblNew n where not exists (select 1 from tblCum c where c.mailid=n.mailid)
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

752 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