Search code examples
javasqljooq

Jooq choose when statement on multiple columns


I have this part of query:

case 
    when columnA = 'On' 
        and columnB <= current_date() 
        and columnC > current_date()
        then columnA
    else 'NoChange'
end) 

is it possible to write it in Jooq, Java?


Solution

  • Just use the CASE expression in jOOQ almost as you would, in SQL.

    // Assuming this static import, as always
    import static org.jooq.impl.DSL.*;
    
    when(T.COLUMN_A.eq("On")
        .and(T.COLUMN_B.le(currentDate()))
        .and(T.COLUMN_C.gt(currentDate())), T.COLUMN_A)
    .else_("NoChange")