sqlite: is there a way to make a conditional OR / COALESCE in the SELECT clause? sqlite: is there a way to make a conditional OR / COALESCE in the SELECT clause? sqlite sqlite

sqlite: is there a way to make a conditional OR / COALESCE in the SELECT clause?


In sql if one operator is null then the expression becomes null, you can use this with the coalesce function to solve this problem easily. Something like this should work (nb not tested):

   COALESCE(TitleSP || " / " || TitleEN,TitleSP,TitleEN,"No Title") as Title

If you can't do it this way then case is the way to go, something like this (will also handle empty strings):

  TitleSP ||   CASE WHEN ((ISNULL(TRIM(TitleSP),"") = "") OR (ISNULL(TRIM(TitleEN),"") = "")) THEN "" ELSE " / " END ||   TitleEN as Title


SELECT CASE WHEN (TitleSP = '' OR TitleSP IS NULL)                THEN COALESCE(TitleEN, '')            WHEN (TitleEN = '' OR TitleEN IS NULL)                THEN TitleSP            ELSE (TitleSP || ' / ' || TitleEN)       END AS Title, ...


SELECT COALESCE(                NULLIF(TitleSP, '') || ' / ' || NULLIF(TitleEN, ''),                 NULLIF(TitleSP, ''),                 NULLIF(TitleEN, ''),                 ''               ), ...