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

Hey! I'm Anil Singh. I author this blog. I'm Active Blogger, Programmer. I love learning new technologies, programming, blogging and participating the forum discussions more...
My Blogs - http://www.code-sample.com and http://www.code-sample.xyz
My Books - Buy Books Online at Best Prices

You Might Also Like
Post a Comment
www.code-sample.com/. Powered by Blogger.