Michael Victor
Michael Victor

Reputation: 891

IF statements on SQL queries

I have the following query :

SELECT id, status from applications

Now, status can either be open, matched, completed. But when the query displays the results, I want open to be displayed as "In Progress", matched as "Approved" and completed as "Realized"

Is this in anyway possible from the SQL Select statement?

Upvotes: 0

Views: 49

Answers (2)

jarlh
jarlh

Reputation: 44796

Use a CASE:

SELECT id,
       case status when 'open' then 'In Progress'
                   when 'matched' then 'Approved'
                   when 'completed' then 'Realized'
       end as status
from applications

Upvotes: 3

Jens
Jens

Reputation: 69470

Try:

   SELECT id, 
           Case status when 'open' then 'In Progress' 
                       WHEN 'matched' then 'approved' 
                       when 'completed' then 'Realized' 
            end 
     from applications

Upvotes: 0

Related Questions