Evgeny
Evgeny

Reputation: 4010

Get value from Firebird cursor by field name

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.

Upvotes: 0

Views: 214

Answers (1)

Mark Rotteveel
Mark Rotteveel

Reputation: 108941

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

Upvotes: 2

Related Questions