I have 2 tables, one that contains the final results I need, and another that contains the list of columns I need to select from based on a set level.
For example :
table_levels
level | name | [selected-columns]
1 | startdate | start_date
1 | end date | end_date
1 | contract | contract
So if i do the following
select column from table_levels where level = '1'
Then basically i need to use the column names from this select statement to determine which columns are selected from another statement.
This is what ive tried and of course i know its wrong but gives you an idea of what im trying to do.
select (select [selected-columns] from table_levels where nwlevel = '1')
from table_results
In a way im trying to dynamically build an sql query which can be altered by whichever columns i put in the table_levels
table.
This should in theory act the same as the following sql query
select start_date, end_date, contract
from table_results
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…