When using a CASE statement, do the values for THEN have to be a single type?


#1

Question

For a CASE statement, do all values provided by THEN have to match a single data type?

Answer

No, for CASE statements, the THEN values do not have to return only a single type of value. In fact, you can have each THEN in a single CASE statement return different value types such as TEXT, REAL, and INTEGER.

Example

SELECT 
  CASE
    WHEN condition1 THEN "text"
    WHEN condition2 THEN 100
    WHEN condition3 THEN 3.14
  END AS 'example'
FROM table;