Solved

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

Posted on 2013-06-25
5
303 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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL DATEADD 10 89
Parsing this XML works but the other one doesn't 9 36
T-SQL: Need to trim a single leading space 7 63
Importing from CSV to SSMS 2 14
     When we have to pass multiple rows of data to SQL Server, the developers either have to send one row at a time or come up with other workarounds to meet requirements like using XML to pass data, which is complex and tedious to use. There is a …
SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

751 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