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
220 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 250 total points
ID: 36473991
INSERT INTO tblCum
SELECT * FROM tblNew WHERE tblNew.MailID NOT IN (SELECT a.MailID FROM tblCum a)
0
 
LVL 52

Expert Comment

by:Huseyin KAHRAMAN
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 52

Assisted Solution

by:Huseyin KAHRAMAN
Huseyin KAHRAMAN earned 250 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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

Suggested Solutions

Introduction: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

726 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