Click here to Skip to main content
15,665,444 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello, i have querry statement that selects from source and with condtion writes in destination but with different databases.

What I have tried:

i have made two shared connections in my project.
Any help guys !
Updated 26-Apr-21 3:42am

1 solution

If the databases are not on the same instance of SQL Server then set up a Linked server - see Create Linked Servers - SQL Server | Microsoft Docs[^]
Then just use fully qualified table names including the server e.g.
select [column1],[column2] -- etc
into [server2].database2.dbo.table2 
from database1.dbo.table1
If they are on the same instance just use the database names
select [column1],[column2] -- etc
into database2.dbo.table2 
from database1.dbo.table1
There are a couple of alternatives - see this article[^]
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900