Select data from Selected table name

  • Hi..

    I have my table name in another table column.

    I want to select rows from that selected table name.

    Using variables, i can do that.

    But with a single query how can i select the data from the target table, whose name is in another table.

    Regards,

    Hanuman

  • You'll have to use dynamic SQL. You can read information_Schema.columns for the table_name to get the columns. Then you can dynamically build the select syntax. Be careful though, if the table has any kind of volume, it will be performing a full-table scan. Also, your ID will need select rights to the table.

    For better, quicker answers, click on the following...
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

    For better answers on performance questions, click on the following...
    http://www.sqlservercentral.com/articles/SQLServerCentral/66909/

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply