What is the best way to convert an int or null to boolean value in an SQL query?

前端 未结 10 1227
情话喂你
情话喂你 2021-02-06 21:07

What is the best way to convert an int or null to boolean value in an SQL query, such that:

  • Any non-null value is TRUE in the results
  • Any
10条回答
  •  余生分开走
    2021-02-06 22:07

    No need to use case... when:

    select (column_name is not null) as result from table_name;
    

    Returns 1 for all fields not NULL and 0 for all fields that are NULL, which is as close as you can get to booleans in SQL.

提交回复
热议问题