Imply bit with constant 1 or 0 in SQL Server

后端 未结 8 1697
一生所求
一生所求 2020-12-13 07:56

Is it possible to express 1 or 0 as a bit when used as a field value in a select statement?

e.g.

In this case statement (which is part of a select statement)

8条回答
  •  盖世英雄少女心
    2020-12-13 08:18

    If you want the column is BIT and NOT NULL, you should put ISNULL before the CAST.

    ISNULL(
       CAST (
          CASE
             WHEN FC.CourseId IS NOT NULL THEN 1 ELSE 0
          END
        AS BIT)
    ,0) AS IsCoursedBased
    

提交回复
热议问题