Jump to content

How can I insert values to table from store procedure in another database SQL server

- - - - -

  • Please log in to reply
2 replies to this topic

#1
rivkic

rivkic

    Newbie

  • Members
  • PipPip
  • 19 posts
I have sql server 2008.
I have two databases: "DB1" and "DB2".
In "DB1" there is a store procedure that has to select values
and insert them to table in "DB2".

I can I do it?
I can I connect to one database from another database?

#2
gokuajmes

gokuajmes

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 518 posts
just a few questions :
are these two databases on the same Server ? if yes then certainly this is possible.
only thing you need to do is create a stored procedure one more time in Db2 changing the using statement at the Head of sp.
something like this:
From
USE DB1
<your sql operations go here>
To
USE DB2
<sql operations with Db2>
then commit the sql stored procedure to db2.
execute the db like below
EXEC SpName param1,param2

Stored procedures are Database specific. This link might also help you
How to run a stored procedure located in one database against another database

#3
rivkic

rivkic

    Newbie

  • Members
  • PipPip
  • 19 posts
Thanks!!!!!!!!!!!!!!!!!!!!




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users