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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:17:45+00:00 2026-05-25T19:17:45+00:00

Is there a way to write a query like: select * from <some number

  • 0

Is there a way to write a query like:

select * from <some number of tables>

…where the number of tables is unknown? I would like to avoid using dynamic SQL. I would like to select all rows from all the tables that (the tables) have a specific prefix:

select * from t1
select * from t2
select * from t3
...

I don’t know how many t(n) might there be (might be 1, might be 20, etc.) The t table column structures are not the same. Some of them have 2 columns, some of them 3 or 4.

It would not be hard using dynamic SQL, but I wanted to know if there is a way to do this using something like sys.tables.

UPDATE

Basic database design explained

N companies will register/log in to my application

Each company will set up ONE table with x columns

(x depends on the type of business the company is, can be different, for example think of two companies: one is a Carpenter and the other is a Newspaper)

Each company will fill his own table using an API built by me

What I do with the data:

I have a “processor”, that will be SQL or C# or whatever.

If there is at least one row for one company, I will generate a record in a COMMON table.

So the final results will be all in one table.

Anybody from any of those N companies will log in and will see the COMMON table filtered for his own company.

  • 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-25T19:17:45+00:00Added an answer on May 25, 2026 at 7:17 pm

    to list ALL tables you could try :

    EXEC sp_msforeachtable 'SELECT * FROM  ?'
    

    you can programmability include/exclude table by doing something like:

    EXEC sp_msforeachtable 'IF LEFT(''?'',9)=''[dbo].[xy'' BEGIN SELECT * FROM  ? END ELSE PRINT LEFT(''?'',9)'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using standard mysql functions is there a way to write a query that will
Is there any way to write a valid header/link/image? Something like <a href=index.html><h1 id=logo>Company
Is there any way to write Shoes application using IDE (NetBeans for example)? I
Is there a way to write a query in LINQ to return the count
I have a query structure like below, Im wondering if there is a way
I would like to write some custom VBA functions to perform calculations on particular
is there a better way to write this SQL than using WHERE ... IN
Is there any way to Write files to App_Data under medium trust hack? Im
Is there a way to write an enumeration that can be extended. I have
Is there a way to write log4j logging events to a log file that

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.