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 8057951
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T09:11:55+00:00 2026-06-05T09:11:55+00:00

The question may not exactly describe what I’d like to do, but I have

  • 0

The question may not exactly describe what I’d like to do, but I have a stored procedure that has a query returning the following columns

ID Title Tablename

The Title is currently being returned as NULL as I need to be able to get it from a JOINED table referenced in the Tablename column. There could be several different Tablename values returned in the query and the Title for each record needs to be got from the Table referenced in the Tablename field for each record.

Is there a pure SQL way of doing this?

I’ve thought about creating a temporary table and then looping through each record and setting the Title by running a seperate query against the table in Tablename, but am hopign for a cleaner solution.

Thanks

  • 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-06-05T09:11:56+00:00Added an answer on June 5, 2026 at 9:11 am

    This may be an indication of a design not directly suited to SQL. What is the reason that your Title information is stored in multiple table? Can it be re-factored to not be so?

    If, however, the list of tables is a fixed list, there is a solution; use UNION ALL in a view, or CTE to use an in-line view, to make your many tables look like one table…

    WITH
      inlineView
    AS
    (
                  SELECT 'table1' AS tableName, x, y, z, title FROM table1
      UNION ALL   SELECT 'table2' AS tableName, x, y, z, title FROM table2
      UNION ALL   SELECT 'table3' AS tableName, x, y, z, title FROM table3
    )
    SELECT
      *
    FROM
      aTable
    INNER JOIN
      inlineView
        ON  aTable.tableName = inlineView.tableName
        AND aTable.x         = inlineView.x
    

    If you can’t make it fit that, or the number of tables you need to include in the view is not fixed, you will probably need a loop and some dynamic SQL. Again, a strong indicator that the schema isn’t really SQL friendly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question may not directly relate to programming. I have noticed that the technology
I concede that this question may fall into the 'discussable' but not 'answerable' category.
I'm not sure exactly how to describe this question, but here goes. I've got
This question may not be exactly programming related, but this is about development. I
I know this may not be exactly a coder question, but I feel it
This question may expose my ignorance as a web developer, but that wouldn't exactly
I have an interesting question, but I'm not sure exactly how to phrase it...
This may not be a programming question, but I don't know where to ask
This may not be the kind of question one should ask on StackOverflow, but
My question may be quite similar to others, but not the same. In the

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.