I've been googling something I dont really cant understand. In short my problem is this;
When using this;
String sYear2 = "2020";
string query = @"Select decJan from Stats where intRecnum = (select intRecnum from Stats where intAr = @year)";
var cmd = new SqlCommand(query, con);
cmd.Parameters.AddWithValue("@year", sYear2);
The result is returning "111" (which is correct vaule of column decJan the year 2020.
But when trying this;
String sYear2 = "2020";
String sColumn2 = "decJan";
string query = @"Select " + @column + @" from tbFuGraddagar where intRecnum = (select intRecnum from tbfuGraddagar where intAr = @year)";
var cmd = new SqlCommand(query, con);
cmd.Parameters.AddWithValue("@year", sYear2);
cmd.Parameters.AddWithValue("@column", sColumn2);
I recieve "decJan" as result.
When googling all I have found that its not possible without dynamic SQL or that is bad design.
But I fail to understand what the diffrence is...all I want is to change the static code with a value similar to @year-parameter. the "interpretation" shouldn't care about the validation of SQL-syntax, it's just a matter och string-manipulation.
Or is it just me beeing a bad C#-coder?