Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
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
?
224 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 60

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 60

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

What’s Wrong with Your Cloud Strategy ?

Even as many CIOs are embracing a cloud-first strategy, the reality is that moving to the cloud is a lengthy process and the end-state is likely to be a blend of multiple clouds—public and private. Learn why multicloud solutions matter in this webinar by Nimble Storage.

Question has a verified solution.

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

In this article I will describe the Backup & Restore 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.
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

636 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