Get value from Firebird cursor by field name

187 Views Asked by At

I need get data from cursor by field name, stored in var. For example, I have statement:

for select CUBE1, CUBE2, CUBE3, ....., CUBE31
    from GET_DATA(......) B
    where ..... as cursor cvol do

And now I need get value from cursor by dynamically changed name

s = 'cube' || extract(day from on_date);
vol = cvol.:s --????

I'm using Firebird 3.

1

There are 1 best solutions below

0
On BEST ANSWER

It is not possible to get a column by name dynamically. The name you want to use must be known at compile time. The best you can do is getting the value by name based on the day in the month using a simple case:

vol = case extract(day from on_date)
  when 1 then cvol.cube1
  when 2 then cvol.cube2
  -- .. and so on
  when 31 then cvol.cube31
end