Given a table name and column name in a pair of variables, can I perform a select query without using dynamic sql?
for example, I'd like something nicer than this:
CREATE PROCEDURE spTest (@table NVARCHAR(30), @column NVARCHAR(30)) AS
DECLARE @sql NVARCHAR(2000)
SELECT @sql = N'SELECT ' + @column + N' FROM ' + @table
PRINT @sql
EXEC sp_executesql @sql
I'd like to do this because my dynamic sql version is 3x slower than the non-dynamic version (which doesn't support a programmable table/column name, hence this question).