SQL Server NULL check in SELECT statement

I have a table that I need to UNION with another one and doing so I need to convert datetime value to true or false regarding on fact the value is or is not NULL.

Little example would be helpful:

ID | Value I have | Value I need |
---+--------------+--------------+
  1|    2018-05-02|          True|
  2|    2018-05-03|          True|
  3|          NULL|         False|

Please, is there any way to do it within SELECT clause? I tried IIF or ISNULL functions but they don't work the way I need.

Upvotes: 0

Views: 420

Answers (1)

TcKs
TcKs

Reputation: 26632

You are looking for CASE WHEN ... THEN ... ELSE ... END prescription.

SELECT
    ID,
    [Value I have],
    CASE WHEN [Value I have] IS NULL THEN 1 ELSE 0 END AS [Value I need]
FROM MyTable;

Upvotes: 1

Related Questions