0

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.

7
  • 3
    CASE WHEN YourColumn IS NULL THEN 'False' ELSE 'True' END Commented May 9, 2018 at 15:21
  • 4
    IIF would do the trick. Show what you did and we can see where it went sideways on you. Commented May 9, 2018 at 15:22
  • 1
    or, using IIF: IIF(YourColumn IS NULL, 'False','True') Commented May 9, 2018 at 15:23
  • IIF is not working in the SELECT Commented May 9, 2018 at 15:26
  • If you provide the statement (and hopefully sample data) users can improve the code. Without the statement we're guessing and you are getting a slower, and possibly incorrect, response. If you have tried IS NULL and not getting the results you are expecting it could be a data problem. Commented May 9, 2018 at 15:30

1 Answer 1

1

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;
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.