Can I pass variable to select statement as column name in SQL Server [duplicate]

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)

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)