SQLite - Case statement

Sqlite Banner

About

The case statement in sqlite

Example

Value based Format

The value base format with the weekday name from its number (o being sunday).

select case cast(strftime('%w', date()) as integer)
           when 0 then 'Sunday'
           when 1 then 'Monday'
           when 2 then 'Tuesday'
           when 3 then 'Wednesday'
           when 4 then 'Thursday'
           when 5 then 'Friday'
           else 'Saturday' end as english_weekday

Conditional expression base case

The conditional based format

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





Discover More
Sqlite Banner
SQLite - Date

The date data type in SQLite context does not exist. It is not an affinity. SQLite are capable of storing dates and times with the following data type (affinity) as: TEXT with ISO8601 strings (“YYYY-MM-DD...



Share this page:
Follow us:
Task Runner