Link to home
Start Free TrialLog in
Avatar of GHR_GDL
GHR_GDL

asked on

Conditionally accesing a possibly non existent table from other DB


Hi, I have a SELECT in a stored procedure that access a table in a database distinct of the
database where this SELECT is, by means of a LEFT JOIN:

SELECT
    A.id, B.id
FROM
     A LEFT JOIN OTHER_DB.dbo.B ON A.Id = B.Id

the thing is, OTHER_DB may not exist, and I want to know if it is possible to use conditional
compilation (or another solution), to have a code that can be used whether that other db exists or
not (using only table A in case OTHER_DB doesn't exists); the only way I can think is simply put
the code that references that db enclosed in commentary marks like this:

SELECT
    A.id--, B.id
FROM
     A --LEFT JOIN OTHER_DB.dbo.B ON A.Id = B.Id

but I'm curious if other more seamless or practical way is possible, in order to maintain more
easily my code, I'm not sure if it possible something like that... thanks in advance.

ASKER CERTIFIED SOLUTION
Avatar of JestersGrind
JestersGrind
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of GHR_GDL
GHR_GDL

ASKER

Lead me to try other stuff that worked for me.