You can’t use variable names to bind columns or other system objects, you need dynamic sql
DECLARE @value varchar(10)
SET @value="intStep"
DECLARE @sqlText nvarchar(1000);
SET @sqlText = N'SELECT ' + @value + ' FROM dbo.tblBatchDetail'
Exec (@sqlText)
More Related Contents:
- SQL group_concat function in SQL Server [duplicate]
- Pivot Dynamic Columns, no Aggregation
- T-SQL: Export to new Excel file
- Enable ‘xp_cmdshell’ SQL Server
- Sql Server ‘Saving changes is not permitted’ error ► Prevent saving changes that require table re-creation
- SQL MERGE statement to update data
- How to get the last record per group in SQL
- How to convert float to varchar in SQL Server
- A transport-level error has occurred when receiving results from the server [closed]
- storing passwords in SQL Server
- How does sql server sort your data?
- How to restore to a different database in SQL Server?
- Why is SQL Server 2008 Management Studio Intellisense not working?
- Reporting Services permissions on SQL Server R2 SSRS
- T-SQL substring – separating first and last name
- How to implement polymorphic associations in an existing database
- How to get week number of the month from the date in sql server 2008
- Optional parameters in SQL Server stored procedure
- Entity Framework Database.SetInitializer simply not working
- Cannot open backup device. Operating System error 5
- Restoring database from .mdf and .ldf files of SQL Server 2008
- What is the default transaction isolation level for SQL Server with ADO.NET?
- Restrict SQL Server Login access to only one database
- T-SQL strip all non-alpha and non-numeric characters
- How can I get a trigger to fire on each inserted row during an INSERT INTO Table (etc) SELECT * FROM Table2?
- Avoiding IF ELSE due to variable been NULL
- SQL Server 2008 Connection Error “No process is on the other end of the pipe”
- SSIS LookUp is not dealing with NULLs like the docs say it should
- Recursive Child/Parent queries in T/SQL
- Forcing code-first to always initialize a non-existent database?