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.
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:
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:
SELECT
CASE
WHEN exists(other query) THEN 'True' --Subquery has record
ELSE 'False' --Subquery has not record
END;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.