Is there a way to reference field name with a variable in Firebird
Is there a way to开发者_C百科 reference field name with a variable value in Firebird ? for example I want to make SQL like this:
Insert into tab1 (1, f1, f2, f3)
select 1, tab2.f+var_loop, tab2.f+var_loop, tab2.f+var_loop
from tab2
where .....
where "f" is the first initial of the field name and "var_loop" is a loop variable Thanks
No, this is not supported. I quess you can achieve something like this using EXECUTE BLOCK, but then you could build the right SQL statement on the client side right away too, would be much easier...
To do this, you must write your application code to build the SQL prior to preparing the query.
In SQL, the name and number of columns must be fixed at the time you prepare the query. Column names can't be based on expressions that aren't evaluated until runtime. This is true in standard SQL and in every brand of RDBMS as far as I know.
Also you can't use parentheses around a list of column in a SELECT clause as you're doing.
精彩评论