Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2008

    Unanswered: Loop through table

    Good Day

    I have a table that stores a couple of tablenames in the same db.
    The tablenames in the table can change from time to time.
    Is it possible to loop through the tablenames in the table and run a query
    against each tablename. I cannot hard code the table names in the query
    because they can change from time to time.
    Not sure how to accomplish this.

    Thank You

  2. #2
    Join Date
    Sep 2001
    Chicago, Illinois, USA
    Google "dynamic SQL".

    Basically, instead of writing queries against fixed table names, you will write a stored procedure that will use T-SQL to write the queries into text strings, and you will then execute the query text strings. By having the stored procedure write the queries, they can be dynamically created at execution time.

    Maverick Software Design

    (847) 864-3600 x2

Posting Permissions

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