Return Boolean Value on SQL Select Statement

后端 未结 9 909
不知归路
不知归路 2021-01-29 21:36

How to return a boolean value on SQL Select Statement?

I tried this code:

SELECT CAST(1 AS BIT) AS Expr1
FROM [User]
WHERE (UserID = 20070022)

9条回答
  •  孤街浪徒
    2021-01-29 21:46

    Given that commonly 1 = true and 0 = false, all you need to do is count the number of rows, and cast to a boolean.

    Hence, your posted code only needs a COUNT() function added:

    SELECT CAST(COUNT(1) AS BIT) AS Expr1
    FROM [User]
    WHERE (UserID = 20070022)
    

提交回复
热议问题