Imply bit with constant 1 or 0 in SQL Server

后端 未结 8 1625
一生所求
一生所求 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:38

    Slightly more condensed than gbn's:

    Assuming CourseId is non-zero

    CAST (COALESCE(FC.CourseId, 0) AS Bit)
    

    COALESCE is like an ISNULL(), but returns the first non-Null.

    A Non-Zero CourseId will get type-cast to a 1, while a null CourseId will cause COALESCE to return the next value, 0

提交回复
热议问题