I have a select menu in my program that grabs values from a table that only has two columns: Rating_ID and Rating_Name. The value it grabs is the Rating_Name.
I then have a table that will want to display information that will be partially contingent on the value from the selected value from that select dropdown.
The thing is, I need to use the Rating_ID in my query, not the Rating_Name. Therefore, I created a variable at the beginning of my SQL statement that grabs the value from the select dropdown and sets the value of the variable to whatever the Rating_ID is for that Rating_Name. I know that works because I've tested it in SQL and it always returns the right value.
The problem I'm having is getting it into the actual Select Statement for the output of my table. Assuming that the variable I've created is called @X and the query is pulling from a table called "Test" and I put in the following code it doesn't work:
SELECT Test.@X from Test
I've tried putting @X in brackets and that doesn't work either.
I have tested putting in the actual integer value (bypassing the variable, but also thus making the output static rather than dynamic based on the select dropdown) and it will work if I use the following code:
SELECT Test.[1] from Test
I've used variables a lot in my program and never had a problem, but I've never used it in a Select Statement and wasn't expecting this to be a problem. I'm wondering if it is my syntax or something else.
Any help would be appreciated!