Specifiying TableNames,ColumnNames as sproc param?

  • Is it possible to specify TableNames, ColumnNames as stored procedure parameters for be used in a SQL statement.

    I have heard the sysname data type could be used, but could not get that working.

    The only way I can think of solving this problem is:

    declare @strSQL varchar(8000)

    set @strSQL ='select ' + @ColumnName + ' from ' + @TableName

    EXEC (@strSQL)

    does anybody have another solution?

    thank you.

    the

  • I believe dynamic Sql is the only way to achieve this, an alternative to using EXEC is sp_executesql which can reuse the execution plan, improving performance.

    Regards,

    Andy Jones

    .

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

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