Passing Table Names into a large script

  • Hi,

    I'm running SQL Server 2000 SP3a on Windows 2003 Advanced Server. I have a large script that creates a trigger.  The script requires the table name to be added three times throughout the script.

    I am wanting to run this script against 200 tables in the same database, and therefore would like to be able to pass through the table name to the script.  I have a separate table that contains all the table names I want to pass through to the script.

    As the script contains "create trigger ....." I cannot put the code within a stored procedure and pass the table name through.

     

    Any ideas?

     

    Thanks in advance.

    www.sqlAssociates.co.uk

  • use vbscript to create and execute the sql

     

     


  • I cannot put the code within a stored procedure and pass the table name through.

    No, you can.

    Just use dynamic SQL.

    Put @TABLENAME@ in your script instead of actual table name.

    SET @SQL = REPLACE(@SQL, '@TABLENAME@', @TableName)

    EXEC (@SQL)

    _____________
    Code for TallyGenerator

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

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