If statements with SQL and returning string values

Sage

I'm using SQL and I need to return one string if the value of a field is 5 and another string if the value of the field is 4. I have something like this right now:

SELECT * FROM tablename WHERE value1=4 OR value1=5;

In PHP for example it might be like this (but I can't use PHP for my application):

if ($value1 == 4) {
 $value1 = 'free';
} elseif ($value1 == 5) {
 $value1 = 'not free';
} elseif...etc.

Anyone know how to accomplish what I want with SQL only?

Gordon Linoff

Then you would do something like:

select (case when value1 = 4 then 'free' else 'not free' end) as newval
from tablename
where value1 in (4, 5);

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related