Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does sqlite support any kind of IF(condition) statement in a select

Tags:

sql

sqlite

Does sqlite support the sql function "if" in the select statement?

for example

select if( length( a ) > 4 , a , ' ') as b from foo 

which would return a if the length was over 4 chars long. or else it would return ' ' as b

If it does support a condition in the select what is the syntax is should be using?

I have checked http://sqlite.org/lang_corefunc.html but I can't see it.

like image 505
Matt Peters Avatar asked Aug 18 '09 15:08

Matt Peters


People also ask

How do I write an if statement in SQLite?

In SQLite, iif() is a conditional function that returns the second or third argument based on the evaluation of the first argument. It's logically equivalent to CASE WHEN X THEN Y ELSE Z END . iif() is an abbreviation for Immediate IF. The iif() function was introduced in SQLite 3.32.

Does SQLite support case statement?

SQLite provides two forms of the CASE expression: simple CASE and searched CASE .

Where multiple conditions SQLite?

The OR operator is also used to combine multiple conditions in a SQLite statement's WHERE clause. While using OR operator, complete condition will be assumed true when at least any of the conditions is true. For example, [condition1] OR [condition2] will be true if either condition1 or condition2 is true.

Which SQLite expressions are used to perform any mathematical operation in any query?

SQLite Numeric expression is used to perform any mathematical operations in the query.


1 Answers

See the case expression.

A CASE expression serves a role similar to IF-THEN-ELSE in other programming languages.

For your example

select case when length(a) > 4 then a else '' end as b from foo 
like image 82
mmmmmm Avatar answered Sep 22 '22 09:09

mmmmmm