• ChrisM@home (10/10/2012)


    You could also use dynamic sql for this.

    CREATE PROCEDURE GetData(@TableName NVARCHAR(120), @Columns NVARCHAR(255))

    AS

    BEGIN

    DECLARE @Query AS NVARCHAR(MAX)

    SET @Query = 'SELECT ' + @Columns + ' FROM ' + @TableName

    EXEC sp_executesql @Query

    END

    GO

    EXEC GetData('t1', 'name')

    GO

    In this example you can specify the columns you want on the output...

    Pedro



    If you need to work better, try working less...