Sqlite - If Statement

Sqlite Banner


Most SQL database does not use the if construct but the conditional case statement to express a condition.


For example where Saturday and Sunday are marked as weekend and the other days as midweek

with day as (select cast(strftime('%w', date()) as integer) as weekday)
select case
           when day.weekday == 0 then 'Weekend'
           when day.weekday == 6 then 'Weekend'
           else 'MidWeek' end as weekpart
from day

Share this page:
Follow us:
Task Runner