Return Boolean Value on SQL Select Statement

后端 未结 9 1089
不知归路
不知归路 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条回答
  •  旧时难觅i
    2021-01-29 21:58

    Notice another equivalent problem: Creating an SQL query that returns (1) if the condition is satisfied and an empty result otherwise. Notice that a solution to this problem is more general and can easily be used with the above answers to achieve the question that you asked. Since this problem is more general, I am proving its solution in addition to the beautiful solutions presented above to your problem.

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

提交回复
热议问题