Using Microsoft SQL 2000, I will like to join multiples tables (A, B, C, and D) together. I know table A always exists. However, I only know at least one of the table form (B, C, D) exists.
Is there any way I could do something like this to accomplish what I am trying to do?
Select * form table a
If table b exists left Join table b on a.id = b.id
If table c exists left Join table c on a.id = c.id
If table d exists left Join table d on a.id = d.id
You’ll have to check the data dictionary views for that and use dynamic SQL
I’ve used
sysobjects, however you are encouraged to use Information Schema Views insteadAnd, a BIG DISCLAINER ON DYNAMIC SQL
Advantages
Disadvantages