Reputation: 53
Can you please help me solve the problem I am having with my query. I am very new in Database programming and I thoroughly search the web for the help but none solve my issue. I am fed up and wondering if this is even possible. What I want to accomplish is to execute a SELECT query where the column to search is to be supplied on runtime. Like this one:
SELECT *
FROM myTable
WHERE @columnToSeach = @_ColumnName
Advice is really appreciated as my brain is practically bleeding on this one.
Upvotes: 3
Views: 225
Reputation: 5220
A very quick solution would be:
execute ('SELECT * FROM myTable WHERE ' + @columnToSeach + '=' + @_ColumnName)
Upvotes: 1