Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. 50 Tables(Urgent)

50 Tables(Urgent)

Scheduled Pinned Locked Moved Database
databasehelp
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kirthikirthi
    wrote on last edited by
    #1

    HI all I have 50 tables in my database In 50 tables the fields are same(Name,year,date these 3 fields only) Now i want write query to retrive all 50 tables information in 1 QUERY Can any one plz help me THX asdfasdfasdfasdfasdfasdfasdfasdfasdfasdf

    M R 2 Replies Last reply
    0
    • K kirthikirthi

      HI all I have 50 tables in my database In 50 tables the fields are same(Name,year,date these 3 fields only) Now i want write query to retrive all 50 tables information in 1 QUERY Can any one plz help me THX asdfasdfasdfasdfasdfasdfasdfasdfasdfasdf

      M Offline
      M Offline
      Michael P Butler
      wrote on last edited by
      #2

      Will a Union Query[^] do the job? Michael CP Blog [^] Development Blog [^]

      1 Reply Last reply
      0
      • K kirthikirthi

        HI all I have 50 tables in my database In 50 tables the fields are same(Name,year,date these 3 fields only) Now i want write query to retrive all 50 tables information in 1 QUERY Can any one plz help me THX asdfasdfasdfasdfasdfasdfasdfasdfasdfasdf

        R Offline
        R Offline
        r stropek
        wrote on last edited by
        #3

        Hi! You can generate the query you need using the following SQL-Statement:

        select 'select [name], [year], [date] from '+table_schema+'.'
        +table_name+' union all '
        from INFORMATION_SCHEMA.TABLES

        Execute this statement with result type = text, copy the result to a new query windoe and delete the last "union all". It will give you a union all of all your tables -> your 50 tables combined into one. Hope this helps. Regards, Rainer Rainer Stropek Visit my blog at http://www.cubido.at/rainers

        K 1 Reply Last reply
        0
        • R r stropek

          Hi! You can generate the query you need using the following SQL-Statement:

          select 'select [name], [year], [date] from '+table_schema+'.'
          +table_name+' union all '
          from INFORMATION_SCHEMA.TABLES

          Execute this statement with result type = text, copy the result to a new query windoe and delete the last "union all". It will give you a union all of all your tables -> your 50 tables combined into one. Hope this helps. Regards, Rainer Rainer Stropek Visit my blog at http://www.cubido.at/rainers

          K Offline
          K Offline
          kirthikirthi
          wrote on last edited by
          #4

          HI Both of u THX for replying My problum is i have an query to search and display so i given query like this select name from '" & textbox1.text & "' where date = ''.... table name come from textbox which is enter by client. now i want to do is to i have to remove the client textbox. And by date or any thing i have search the names which is in 50 tables 50 table names i have to display PLZ help me THX asdfasdfasdfasdfasdfasdfasdfasdfasdfasdf

          R M 2 Replies Last reply
          0
          • K kirthikirthi

            HI Both of u THX for replying My problum is i have an query to search and display so i given query like this select name from '" & textbox1.text & "' where date = ''.... table name come from textbox which is enter by client. now i want to do is to i have to remove the client textbox. And by date or any thing i have search the names which is in 50 tables 50 table names i have to display PLZ help me THX asdfasdfasdfasdfasdfasdfasdfasdfasdfasdf

            R Offline
            R Offline
            r stropek
            wrote on last edited by
            #5

            Hi! Ok, I think I understand your problem. You have to change my SQL generation query like this:

            select 'create view MyHelperView as '
            union all
            select 'select [name], [year], [date], '
            +''''+table_name+''' as tablename from '+table_schema+'.'
            +table_name+' union all '
            from INFORMATION_SCHEMA.TABLES

            This query generates a helper view that you can use in your program. It contains a new colum named "tablename" that you can display. Therefore your query could look like this:

            select tablename, name from MyHelperView where date = ...

            Hope this helps! Regards, Rainer. Rainer Stropek Visit my blog at http://www.cubido.at/rainers

            1 Reply Last reply
            0
            • K kirthikirthi

              HI Both of u THX for replying My problum is i have an query to search and display so i given query like this select name from '" & textbox1.text & "' where date = ''.... table name come from textbox which is enter by client. now i want to do is to i have to remove the client textbox. And by date or any thing i have search the names which is in 50 tables 50 table names i have to display PLZ help me THX asdfasdfasdfasdfasdfasdfasdfasdfasdfasdf

              M Offline
              M Offline
              Mahesh Sapre
              wrote on last edited by
              #6

              The solution provided by r.stropek is good. Basically I surprise, why do you maintain 50 tables of same structure?:confused: Can you not combine all the 50 tables into one table (with one additional column as TableName or Type or Category or anything like that)? (r.stropek suggests to do this through a view.) I guess combining tables will solve maintenance problem, and help normalization too!

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups