T-SQL update dynamic tabels

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kgoldvas
    New Member
    • Sep 2007
    • 2

    T-SQL update dynamic tabels

    hello

    I am sure this is a simple Q, but I am not that familar with T-SQL so...
    any how, I have dynamic tables taht I can fetch from this query:
    SELECT NAME FROM SYSOBJECTS WHERE (NAME LIKE 'PW_OSSS%' OR NAME LIKE 'PW_OSPS%') AND TYPE = 'U';

    and I need to run on them the Alter command
    ALTER TABLE <dinamic table name that return from the select>MODIFY OSPS_IO_SUM NUMBER (18,6);
    ALTER TABLE <dinamic table name that return from the select> MODIFY OSPS_IO_SUM NUMBER (18,6);
    ALTER TABLE <dinamic table name that return from the select> MODIFY OSPS_IO_SUM NUMBER (18,6);

    I would like to know how will I write the T-SQL transact (procedure) in order to be able to upgrade the column in the dynamic tables that return from the select query?

    Thanks
  • kgoldvas
    New Member
    • Sep 2007
    • 2

    #2
    I will try to be more specific
    this is the query that I run to have all the tables that I want to update

    SELECT PWPR_PARTITION_ NAME FROM PS_PWPR_PARTITI ON_RANGE
    WHERE PWPR_TABLE_NAME LIKE 'PW_OSSS%'
    OR PWPR_TABLE_NAME LIKE 'PW_OSPS%'

    I want to run on each table that return and alter the table for example

    ALTER TABLE PW_OSPS_PROC_ST ATISTICS_PU_T MODIFY OSPS_IO_SUM NUMBER (18,6);

    how can I do it in one T-SQL command please

    Comment

    • ck9663
      Recognized Expert Specialist
      • Jun 2007
      • 2878

      #3
      Originally posted by kgoldvas
      I will try to be more specific
      this is the query that I run to have all the tables that I want to update

      SELECT PWPR_PARTITION_ NAME FROM PS_PWPR_PARTITI ON_RANGE
      WHERE PWPR_TABLE_NAME LIKE 'PW_OSSS%'
      OR PWPR_TABLE_NAME LIKE 'PW_OSPS%'

      I want to run on each table that return and alter the table for example

      ALTER TABLE PW_OSPS_PROC_ST ATISTICS_PU_T MODIFY OSPS_IO_SUM NUMBER (18,6);

      how can I do it in one T-SQL command please

      you could use a CURSOR. fetch/loop on the entire result set. store the ALTER query to a variable to make the table name dynamic and do an EXEC(@yoursqlva riable)

      Comment

      Working...