Combining select from boolean

Hi guys, could you please help me here.

SELECT e.name, IF e.active = 0 THEN e.active = true WHERE e.id = # {property_id} ELSE e.active = false WHERE e.id = # {property_id} END IF AS Estate_status FROM estates e

-1


a source to share


3 answers


This is db2 syntax as you didn't specify which DB you are using:



select e.name,
    case when e.active = 0 then 'TRUE'
        else 'FALSE'
    end AS Estate_status,
    from estates e
where e.id = #{estate_id}

      

+4


a source


usage example: SELECT e.name (case when e.active = 0 THEN e.active = 1 ELSE e.active = 0 END) AS Estate_status FROM estates e WHERE e.id = # {property_id}



+1


a source


I am confused by the rest of your SQL statement. What exactly are you trying to achieve.

However, regarding the question itself, you cannot use an IF statement in SQL. However, you can use CASE status, for example:

CASE
    WHEN e.active = 0 THEN 'true'
    ELSE 'false'
END

      

0


a source







All Articles