For example
SELECT (SELECT col_name FROM column_names WHERE col_id = 1) FROM my_table
It returns the value of col_name instead of the value of table.col_name
e.g. if col_name is x1 then the above select will return “x1” instead of the value of SELECT x1 FROM my_table
Is there a way to do it in
- Microsoft SQL Sever 2008? (based on the answers, seems that yes)
- Oracle 11g?
If it is, how can I use the select clause columns in a where clause without repeating the subselect?
In SQL Server you can use dynamic SQL, something like this: