Skip to content

HowToCalculatedField

iraichi edited this page Apr 24, 2015 · 5 revisions

How to define a Calculated Field

Please refer to here for general informations about models.

Kitto allows you to define fields as the result of a SQL expression calculated on the fly. These are fields that do not exist in the underlying database table but are needed in the application.

Use the Expression node: Expressions may contain macros, and particularly database-scoped macros (those with a DB. prefix) to help writing database-independent code. It is conveniente to qualify fields using the standard {Q} qualifier.

Example from [TasKitto](Taskitto]:

# model Activity.yalm
ModelName: ACTIVITY
...
Fields:
....
  START_TIME: Time
  END_TIME: Time
  DURATION: Float
    DisplayWidth: 8
    Expression: |
      case
        when (ACTIVITY.START_TIME is null) or (ACTIVITY.END_TIME is null) then 0
        else (ACTIVITY.END_TIME - ACTIVITY.START_TIME) / 3600
      end

Clone this wiki locally