Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Creating temp table in a different database

Author  Topic 

n4nature
Starting Member

7 Posts

Posted - 2012-10-03 : 16:45:28
I am trying to extract a part of data into a temp table on a different database on a separate SQL server. Here's the query for that:


SELECT [DB1].[dbo].T1 .Col1, [DB1].[dbo].T2 .Col1, [DB1].[dbo].T1 .Col2, [DB1].[dbo].T2.Col2
INTO [DB2].dbo.DB2
FROM [DB1].[dbo].T1


It's not recognizing DB2 here. When I run this query under SQL Server Management Studio, it gives an error:

Database 'DB2' does not exist.

If I comment out the line2 in above query, it compiles and works fine.

Any idea on how to fix this problem?

chadmat
The Chadinator

1974 Posts

Posted - 2012-10-03 : 16:52:00
You need to have a linked server to the other server. How would SQL know what server you are talking about?

-Chad
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-10-03 : 17:28:33
see this to understand what all you need to do to add a linked server

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=164892

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -