• There's two options for you.

    One way is you have a stored procedure that will take the table name, and will have a series of IF-ELSE statements, each of which simply invokes a stored procedure that handles that particular table.

    The other way is to use dynamic SQL. You can use the sp_executeSQL command. See this page for more details: http://msdn.microsoft.com/en-us/library/ms188001.aspx.

    Basically you'd do something like this:

    CREATE PROCEDURE sp_DynamicSQL

    (

    @TableName VARCHAR(MAX)

    )

    AS

    BEGIN

    DECLARE @Statement VARCHAR(MAX)

    SET @Statement = 'SELECT * FROM ' + @TableName ' WHERE 1 = 1 '

    EXEC sp_executeSQL @Statement

    END

    More details on the exact functionality can be found on that page.