Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7159553
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:15:01+00:00 2026-05-28T13:15:01+00:00

Using Microsoft SQL 2000, I will like to join multiples tables (A, B, C,

  • 0

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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T13:15:02+00:00Added an answer on May 28, 2026 at 1:15 pm

    You’ll have to check the data dictionary views for that and use dynamic SQL

    declare @myquery varchar(1000)
    
    set @myquery = 'Select * from a '
    if exists (select * from sysobjects where xtype='U' and name = 'b')
    begin
       set @myquery = @myquery + 'inner join b on b.id = a.id '
    end
    if exists (select * from sysobjects where xtype='U' and name = 'c')
    begin
       set @myquery = @myquery + 'inner join c on c.id = a.id '
    end
    if exists (select * from sysobjects where xtype='U' and name = 'd')
    begin
       set @myquery = @myquery + 'inner join d on d.id = a.id '
    end
    
    exec( @myquery)
    

    I’ve used sysobjects, however you are encouraged to use Information Schema Views instead

    And, a BIG DISCLAINER ON DYNAMIC SQL

    Advantages

    • It gives flexibility and scalability
    • It can reduce the number of lines of code written

    Disadvantages

    • It can become very complex and difficult to read. Think about quotes embedded in quotes, and other such things.
    • It can have a detrimental effect on code stability. Some Dynamic SQL errors will not be known until run time. (An example of this is where you reference a non-existent table)
    • Dynamic SQL code is harder to test than the equivalent static SQL. It may also be impossible to test for every possible circumstance that your Dynamic SQL will encounter, thus introducing inherent risk.
    • It will be more difficult to conduct an effective impact analysis on Dynamic SQL in your code-base.
    • SQL injection and misuse – Dynamic SQL is more prone to misuse, and is invariably less safe than static SQL
    • The queries code within Dynamic SQL is not subject to a query plan, and as such optimisations may be missed. As such, it can be slower than the equivalent static SQL
    • As the SQL query is not known until runtime, it can be harder to performance-tune SQL Dynamic code (for example, determining the indexes that might be required on a table)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using Microsoft SQL server, and I would like to know if it is
I am using Microsoft SQL Server. I have a Table which had been updated
I've created a table in Microsoft Sql CE that I'm using to hold some
A table exists in Microsoft SQL Server with record ID, Start Date, End Date
I am migrating to Delphi 2010 and I am using Microsoft SQL 2000 (Planning
I am creating a new table in Microsoft SQL server 2000 by writing the
Using Microsoft Sql 2000 I have a requirement to be able to email a
I'm using Microsoft SQL Server 2000 and need to convert my time column to
Using Microsoft SQL Server 2008. I have a table of interest rates. I've manually
Using SQL Server 2000 and Microsoft SQL Server MS is there a way to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.