Is there any way how to do that? This does not work:
SqlCommand command = new SqlCommand("SELECT @slot FROM Users WHERE name=@name; ");
prikaz.Parameters.AddWithValue("name", name);
prikaz.Parameters.AddWithValue("slot", slot);
The only thing I can think of is to use SP and declare and set the variable for the column. Seems to me a bit ackward.
You cannot do this in regular SQL – if you must have configurable column names (or table name, for that matter), you must use dynamic SQL – there is no other way to achieve this.
and then use the
sp_executesqlstored proc in SQL Server to execute that SQL command (and specify the other parameters as needed).Dynamic SQL has its pros and cons – read the ultimate article on The Curse and Blessings of Dynamic SQL expertly written by SQL Server MVP Erland Sommarskog.