[FIXED] Returning custom values based on query results

Issue

Is it possible to make a query that returns a different custom value based on a query? Here is an example:

What I have in the table ...

class="s-table">
number
1
2
3

... and this is what I want returned:

number
one
two
three

How can this be done?


Solution

You want a case statement. Depending on your flavor of SQL, something like this should work:

select 
    bar = case 
               when foo = 1 then 'one'
               when foo = 2 then 'two'
               else 'baz' 
          end
from myTable 


Answered By - Chase
Answer Checked By - Pedro (sql.easybugfix Volunteer)

Related Posts

Post a Comment