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)
 select Insert

Author  Topic 

moiseszaragoza
Starting Member

8 Posts

Posted - 2008-10-14 : 15:18:35
I have 2 DBs and i want to write a select query from 1 Db and insert into a diferent db in the same server

how do i do this?

Thanks

Just keep smiling

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-10-14 : 15:19:50
Use the three-part naming convention:

INSERT INTO db1.dbo.Table1 (Column1, Column2)
SELECT Column2, Column2 FROM db2.dbo.Table1

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

ursangel
Starting Member

17 Posts

Posted - 2008-10-29 : 11:46:47
INSERT INTO [db1]..[Table1](Column1, Column2)
SELECT Column2, Column2 FROM [db2]..[Table1]


Regards
Angel
Go to Top of Page
   

- Advertisement -