Thanks.
It seems quite a bit more verbose than the IF() function, but it works, so I
can't complain.
I played with it a bit, and I did notice there are two forms: CASE expr WHEN
and CASE WHEN
When I accidentally put an expr (CASE expr WHEN) *AND* explicit WHEN
conditions rather than values, there was no syntax error and the result was
unexpected:
Example:
drop table if exists a;
create table a(a);
insert into a values(2),(10),(128);
select * from a;
select a,case when a<10 then 1 when a < 20 then 2 else 3 end cased from
; -- gives expected result 1,2,3
select a,case a when a<10 then 1 when a < 20 then 2 else 3 end cased from
a; -- gives unexpected result 3,3,3 and no syntax error
As you can see, the second select gives unexpected output, and according to
the syntax diagram it's not supposed to be a valid variation of the CASE
statement. Is that normal?
-----Original Message-----
From: RSmith
Sent: Tuesday, October 07, 2014 12:23 PM
To: General Discussion of SQLite Database
Subject: Re: [sqlite] Is there equivalent to MySQL IF() function?
SELECT CASE WHEN (AGE<3) THEN 'Baby' WHEN (AGE BETWEEN 4 AND 18) THEN
'Child' ELSE 'Adult' END
On 2014/10/07 11:15, Tony Papadimitriou wrote:
Hi all,
Is there any an equivalent function to the MySQL
IF(condition,true_expr,false_expr) function?
For example, SELECT AGE,IF(AGE < 3,"BABY",IF(AGE < 18,"CHILD","ADULT"));
If not, please add to wish list :)
TIA
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users