Home Forums SQL Server 2005 T-SQL (SS2K5) pass table name as a parameter in stored procedure RE: pass table name as a parameter in stored procedure

  • To be safe, you should add brackets around the table name in bitbucket's code.

    Also, I strongly suggest using an alias on the table name instead of repeating the full table name throughout the query.

    So:

    SET @sSQL = 'SELECT t1.Funder, t1.[Facility ID] FROM ' +

    '[' + @tablename + '] AS t1'

    PRINT @sSQL

    Scott Pletcher, SQL Server MVP 2008-2010