using CASE WHEN in a select statement

I use the following to select an operator with a case. The column that CASE applies to is True, False, and Null. I am trying to display True for True and False for False and Null. But this gives me an error message:

Msgstr "Conversion failed while converting varchar 'Null' value to data type bit."

This is my request:

    case
       when prog.has_post_calc_screen = ''True'' then ''True''
       when prog.has_post_calc_screen = ''False''then ''False''
       when prog.has_post_calc_screen = ''Null'' then ''False''
    End as Referal_ID,

The input I give is:

 '1','ALL', 'ALL'
+5
source share
3 answers

Instead, when prog.has_post_calc_screen = ''Null''write when prog.has_post_calc_screen IS NULLTHEN ... (You can also write ELSE ...because you already processed true and false, so the only possible value is NULL).

UPDATE You can also write

 case
   when prog.has_post_calc_screen = true then 'True'
   else 'False'
 END ....
+3

NULL =. IS NULL , CASE:

when prog.has_post_calc_screen IS NULL then ''False''
+1
when COALESCE(prog.has_post_calc_screen,''False'') = ''False''then ''False''
+1

All Articles