Wednesday, March 21, 2012

How to refer from a stored procedure to a table in another dat

"Bob Barrows [MVP]" wrote:

> Two options that I can think of:
> 1.A series of IF statements, which I'm pretty sure would be the solution o
f
> choice, given that you don't have more than 10 or so databases ...
> 2. Another option is to create a view that unions the tables including a
> column for source database name (I think this is how partitioning is
> implemented )
1. Could you describe in more details how first way will help me to pass a
database name as a parameter. Database name must not be hardcoded in any for
m
even not in several IFs.
2. I can not do anything beforehand. The procedure is guaranteed to be given
a database of certain structure. That is all.
Thanks for replyAlexander Korol wrote:
> "Bob Barrows [MVP]" wrote:
>
> 1. Could you describe in more details how first way will help me to
> pass a database name as a parameter. Database name must not be
> hardcoded in any form
Why not? You're not creating db's dynamically are you?

> even not in several IFs.
IF @.dbname = thisdb
select ... from thisdb..table
IF @.dbname = thatdb
select ... from thatdb..table
...
But if what you say is true, this method is ruled out.

> 2. I can not do anything beforehand. The procedure is guaranteed to
> be given a database of certain structure. That is all.
>
Then you are forced to use dynamic sql ... ugh!!
Somebody needs to rethink this architecture ...
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.

No comments:

Post a Comment