Solved

copy records from one identical table to another identical table on two different datbases

Posted on 2013-06-25
5
304 Views
Last Modified: 2013-06-26
I have database1 with tblAttendance.   I also have database2 with tblAttendance.  There is a column in the table called Redetermination which determines which records will be migrated to the new database and table.

I would like to transfer all records from dbo.database1.tblAttendance where tblAttendance.Redetermination = 1   to dbo.database2.tblAttendance

How can I do that using SQL statments.  Unless there is also a wizard that does this function...
0
Comment
Question by:al4629740
[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
  • 2
5 Comments
 
LVL 12

Expert Comment

by:duttcom
ID: 39276813
Try this -

SELECT *
INTO dbo.database2.tblAttendance
FROM dbo.database1.tblAttendance
WHERE dbo.database1.tblAttendance.Redetermination = '1'
0
 
LVL 22

Accepted Solution

by:
Steve Wales earned 500 total points
ID: 39276825
Actually SELECT ... INTO won't work in this instance.

SELECT INTO creates a new table.  If the destination table already exists, you'll get an error.

You'd want to do something more like this:

INSERT INTO database2.dbo.tblAttendance
SELECT * from database1.dbo.tblAttendance
where database1.dbo.tblAttendance.Redetermination = 1
0
 
LVL 12

Expert Comment

by:duttcom
ID: 39276878
My bad! sjwales is spot-on , sorry for the confusion.
0
 
LVL 22

Expert Comment

by:Steve Wales
ID: 39276907
EDIT: Oops, replied to wrong Question :)
0
 
LVL 9

Expert Comment

by:sarabhai
ID: 39277016
INSERT INTO database2.dbo.tblAttendance(field1, field2, field3,Redetermination)
     SELECT field1, field2, field3 , 1 as Redetermination
     FROM database1.dbo.tblAttendance
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…

623 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