Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

how to move data from one table to another table Expand / Collapse
Author
Message
Posted Tuesday, July 29, 2014 1:31 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Today @ 1:45 AM
Points: 62, Visits: 90
i have a table attendance_details in both database DB1 and DB2, i need to move 01/7/14 and 02/7/14 records from db1 to db2,
My table contains

employee_no INT,
date_of_attendance datetime,
present varchar(20),
shift_type VARCHAR(20),
marked_by VARCHAR(50)

can anyone help me?
Post #1597172
Posted Tuesday, July 29, 2014 1:36 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 6:15 AM
Points: 13,730, Visits: 10,684
INSERT INTO db1.dbo.attendance_details(employee_no,date_of_attendance,present,shift_type,marked_by)
SELECT employee_no,date_of_attendance,present,shift_type,marked_by
FROM db2.dbo.attendance_details
WHERE date_of_attendance IN ('2014-07-01','2014-07-02');





How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?

Member of LinkedIn. My blog at LessThanDot.

MCSA SQL Server 2012 - MCSE Business Intelligence
Post #1597173
Posted Tuesday, July 29, 2014 1:50 AM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Today @ 1:45 AM
Points: 62, Visits: 90
thnak u
Post #1597177
Posted Tuesday, July 29, 2014 1:52 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: 2 days ago @ 7:23 AM
Points: 5,074, Visits: 11,852
Koen Verbeeck (7/29/2014)
INSERT INTO db1.dbo.attendance_details(employee_no,date_of_attendance,present,shift_type,marked_by)
SELECT employee_no,date_of_attendance,present,shift_type,marked_by
FROM db2.dbo.attendance_details
WHERE date_of_attendance IN ('2014-07-01','2014-07-02');



Might need to tweak your filter a bit:
--
WHERE date_of_attendance >= '2014-07-01' and date_of_attendance < '2014-07-03'



Help us to help you. For better, quicker and more-focused answers to your questions, consider following the advice in this link.

When you ask a question (and please do ask a question: "My T-SQL does not work" just doesn't cut it), please provide enough information for us to understand its context.
Post #1597179
Posted Tuesday, July 29, 2014 1:53 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 6:15 AM
Points: 13,730, Visits: 10,684
Phil Parkin (7/29/2014)
Koen Verbeeck (7/29/2014)
INSERT INTO db1.dbo.attendance_details(employee_no,date_of_attendance,present,shift_type,marked_by)
SELECT employee_no,date_of_attendance,present,shift_type,marked_by
FROM db2.dbo.attendance_details
WHERE date_of_attendance IN ('2014-07-01','2014-07-02');



Might need to tweak your filter a bit:
--
WHERE date_of_attendance >= '2014-07-01' and date_of_attendance < '2014-07-03'


Ah yes, the data type is datetime and not date. Nicely spotted.




How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?

Member of LinkedIn. My blog at LessThanDot.

MCSA SQL Server 2012 - MCSE Business Intelligence
Post #1597180
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse