Home All Groups Group Topic Archive Search About

Selecting Data from one DB and Inserting into another DB

Author
19 Aug 2005 7:13 PM
Danny Cary
Is it possible to use a stored procedure to select data from one database and
insert the data into another database? The stored procedure would be located
in the database from which the data would be selected.

Author
19 Aug 2005 7:19 PM
Alejandro Mesa
See "select" statement and four part names in BOL.

Example:

use northwind
go

select orderid, customerid, orderdate
into pubs.dbo.tmp
from dbo.orders

if object_id('pubs.dbo.tmp') is not null
    drop table pubs.dbo.tmp
go


AMB

Show quote
"Danny Cary" wrote:

> Is it possible to use a stored procedure to select data from one database and
> insert the data into another database? The stored procedure would be located
> in the database from which the data would be selected.
>
>
Author
19 Aug 2005 7:23 PM
Robbe Morris [C# MVP]
Yes, you just need to use the fully qualified name of the objects

insert into DataBaseA.dbo.TableA
  select blah
     from DatabaseB.dbo.TableB

If it is on another server, it is something like this...

insert into ServerName.DataBaseA.dbo.TableA
  select blah
     from ServerName.DatabaseB.dbo.TableB



--
Robbe Morris - 2004/2005 Microsoft MVP C#

Earn money answering .NET Framework
messageboard posts at EggHeadCafe.com.
http://www.eggheadcafe.com/forums/merit.asp



Show quote
"Danny Cary" <Danny C***@discussions.microsoft.com> wrote in message
news:B114B228-C312-4FB9-BCB2-EFE29739F751@microsoft.com...
> Is it possible to use a stored procedure to select data from one database
> and
> insert the data into another database? The stored procedure would be
> located
> in the database from which the data would be selected.
>
>
Author
19 Aug 2005 8:28 PM
Danny Cary
I'm ashamed. That was too easy.

Thanks so much for the quick response. I am new to the site and did not
realize help was so easily available.

Show quote
:-)

AddThis Social Bookmark Button