Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2012
    Posts
    3

    Unanswered: Multiple Table Query.

    Hi all, I am new here. Need some help. I have a database that has 370 tables that match %_REF_% naming. All of these tables have a column call ds_name.
    I need to get a list of all values of ds_name for each table. Can anyone help please.

  2. #2
    Join Date
    Jun 2012
    Posts
    3
    This gives me the list of table name:

    select name from sys.tables
    where name like '%_ref_%'

    But then want to select the ds_name value for each of these tables

  3. #3
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    Holy Cow...what a bad design (This is a rude comment and I apologize)

    You need to let this run, the take the generated code, and execute that

    SELECT 'SELECT DISTINCT ds_name FROM ' + TABLE_NAME + ' UNION '
    FROM INFORMATION_SCHEMA.Tables
    WHERE TABLE_NAME LIKE '%_REF_%'

    Just remove the last UNION and Run that

    Do you need to know that count of each value, or the source of where the value comes from?
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

  4. #4
    Join Date
    Jun 2012
    Posts
    3
    Thanks for the reply Brett.

    Preferably results would be Table Name: ds_name

    Or at least have the results grouped by Table
    Last edited by mrmmartian; 06-07-12 at 02:56.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •