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

    Unanswered: Simple yet difficult SQL question

    Hi All,

    I am trying to do something very simple, but for the life of me I cannot figure out how to do it. Here is a snippet of what I mean:-

    declare @table_name varchar(30)

    select @table_name="MY_DATA"

    update statistics @table_name

    This also applies in trying to select data from a table name which is stored in a variable. Is there anyway around this !!??

    Thanks !!

  2. #2
    Join Date
    Mar 2001
    Lexington, KY
    I presume this is in a stored procedure?

    declare @table_name varchar(30)
    declare @sql varchar(whatever)

    select @table_name = "MY_DATA"
    select @sql = "UPDATE STATISTICS " + @table_name

    exec( @sql )

    There exist procedures out there to update all the tables in your DB, for example.


Posting Permissions

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