[英]Use a case expression on resultset?
I'm trying to write a SQL query with case and the conditions of the case is dependent on whether any records are found on a sub-query.我正在尝试使用案例编写 SQL 查询,案例的条件取决于是否在子查询中找到任何记录。
Select
Case When (Another Select statement which may return results) 'True'
Else 'False'
End As Has_Results
From TBL_ABC
You want an EXISTS
condition in a CASE
expression:您需要在CASE
表达式中使用EXISTS
条件:
Select Case
When Exists (
Another Select statement which may return results
)
Then 'True'
Else 'False'
End As Has_Results
From TBL_ABC
You can use EXISTS:您可以使用 EXISTS:
SELECT
CASE
WHEN exists(other query) THEN 'True' --Subquery has record
ELSE 'False' --Subquery has not record
END;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.