How to select true false based on column value in SQL Server?

How to select true false based on column value in SQL Server?

Hello everyone, today's I am going to share the query for  select true and false based on column value using the SQL CASE as given below.

CASE WHEN ColumnName IS NULL THEN 'False' ELSE 'True' END

In the below example, UNIT is a table name and UNITID, UNIT and UPDATEDATE is the columns name. Here I using the case on UPDATEDATE column.

For the detail you can see the example.

SELECT  E.UNITID,
    E.UNIT,
    CASE
        WHEN E.UPDATEDDATE IS NULL THEN 'NOT UPDATED'
        ELSE 'UPDATED'
    END AS RTURNING

FROM UNIT E

--OR

SELECT  MP.MASTERPLANID,
    MP.DISPLAYNAME,
            CASE
                        WHEN MP.MOBILENO IS NULL THEN 'False'
                        ELSE 'True'
            END AS ADDONS
             
FROM MASTERPLAN MP WHERE MP.EQUIPMENTID=8


Please see the live output as given in below screen.













Thank you!
ANIL SINGH

Anil Singh is an author, tech blogger, and software programmer. Book writing, tech blogging is something do extra and Anil love doing it. For more detail, kindly refer to this link..
My Blogs - https://code-sample.com and https://code-sample.xyz
My Book1 - BEST SELLING ANGULAR BOOK (INCLUDING ALL VERSIONS 2, 4, 5, 6, 7)
My Book2 - ANGULAR 2 INTERVIEW QUESTIONS BOOK - Both Books are Available on WorldWide.

www.code-sample.com/. Powered by Blogger.