I am passing dynamic column name base that column name to get the value and below i my table
Table_CandidateInfo
Id Name Age City
1 Mazhar 30 Gulbarga
20 Khan 29 Bidar
Example1
Declare @ColumnName varchar(100), @Id int
set @ColumnName='Age'
set @Id=20
select * from Table_CandidateInfo where ID=@Id and
I am not able to pass ColumnName with and
query because column name is dynamic pass by code. My output should be
29
Example2: If my @ColumnName='City' and @Id=20 then output should be like below
Bidar
I think what you are actually after is the below:
Alas, you cannot pass identifiers as parameters. You need to use dynamic SQL: