[英]SQL Server Exists return type
What does the SQL Server Exists
function return as a type? SQL Server
Exists
函数作为一种类型返回什么?
Does Exists
have a conceptual return type? Exists
是否具有概念返回类型?
SELECT *
FROM tableName
WHERE EXISTS (SELECT *
FROM tableName
WHERE columnName LIKE 'theValue%') = 1
Why does this not work? 为什么这不起作用?
Result Types
结果类型
Boolean
布尔
It has a return type of boolean but this is just an internal datatype currently you can't declare columns or variables of that datatype. 它有一个返回类型的布尔值,但这只是一个内部数据类型,目前你不能声明该数据类型的列或变量。
Or use it in comparisons - even against another boolean. 或者在比较中使用它 - 甚至与另一个布尔值相对应。
where exists(select 1) = exists(select 1)
Also fails. 也失败了。
SQL Server doesn't implement the SQL Standard boolean datatype yet - the closest equivalent is bit
but this is not a true boolean. SQL Server尚未实现SQL Standard布尔数据类型 - 最接近的等价物是
bit
但这不是真正的布尔值。
Exists specifies a subquery to test for the existence of rows and returns boolean(True if any row exists else false). Exists指定一个子查询来测试行的存在并返回boolean(如果存在任何行则返回True,否则返回false)。 Microsoft docs So your code should be
Microsoft docs所以你的代码应该是
SELECT *
FROM tableName
WHERE EXISTS (SELECT *
FROM tableName
WHERE columnName LIKE 'theValue%')
This will return all rows from table 'tableName' IF any one of the rows has 'columnName ' as 'theValue%' ELSE none of the rows will be returned. 这将返回表'tableName'中的所有行。 如果任何一行的'columnName'为'theValue%' ELSE ,则不会返回任何行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.