New Topic Copy table to another database? (Table Exists)

knockyo

Well-known member
Joined
Sep 20, 2006
Messages
78
Programming Experience
1-3
How to copy from one table to another database? (Whether it exists or not i also need to insert records inside)??

the script below only allow me execute 1 time. If i need to insert the new records inside the same table, how it can be done?

SELECT HOURLY_OUTPUT.*
INTO DB_ARCHIVE.dbo.HOURLY_OUTPUT
FROM HOURLY_OUTPUT
WHERE dateadd(day, 0, datediff(day, 0, DT))< dateadd(day, 0, datediff(day, 0, dateadd(day, -60, getdate())))

hope you all can guide me. thanks :D
 
thanks your idea.

if the table not exists how the script can be run?

besides, i need to copy from 1 database table to another database table .

:p
 
you can query against the schema to check if the table exist then run appropriate code
VB.NET:
IF EXISTS (SELECT 1 FROM INFORMATION_SCHEMA.TABLES 
WHERE TABLE_TYPE='BASE TABLE' AND TABLE_NAME='NEWTABLE') 
  SELECT INTO BLAH BLAH BLAH
ELSE -- THIS WILL CREATE THE TABLE
  SELECT * INTO NEWTABLE FROM OLDTABLE
 
Back
Top