Showing posts with label differentclients. Show all posts
Showing posts with label differentclients. Show all posts

Friday, March 23, 2012

Passing DB as parameter to stored procedure

I'm working with an application that has multiple databases for different
clients. I have a stored procedure that I would like to use for all of
these databases that is stored in a separate database. In the past, I have
passed the database name to the stored procedure and used dynamic sql to
build the select statements. In this case, I need to select to a temporary
table and then have a second query that uses the data in the temporary
table. With dynamic sql, the temporary table is removed after the first
query finishes, so this approach won't work.
Is there a way to switch databases in a stored procedure? In the foxpro
days, I think there was a Set Database procedure that would allow you to do
this.
TIA,
JohnSee: http://www.sommarskog.se/dynamic_sql.html
There is a section which explains getting data from another database.
Anithsql