我有以下检查结果集的案例陈述,
SELECT
CASE
WHEN EXISTS(
select CE_Issuedate from t_Certificate
where CE_CertID_pk = (select IT_certID_fk_ind from t_item
where IT_rfileID_fk = '1482'
group by IT_rfileID_fk)
)
THEN (select CE_Issuedate from t_Certificate
where CE_CertID_pk = (select IT_certID_fk_ind from t_item
where IT_rfileID_fk = '1482'
group by IT_rfileID_fk))
ELSE NULL
END AS 'CE_Issuedate';
我想在此select语句中没有结果时返回NULL。我试过这样但我不确定这是否正确。这个查询正在运行,但我认为没有结果时返回字符串值。
以下脚本返回如下:
但我认为实际上它想要像这样,
请帮帮我。这是对的吗?
答案 0 :(得分:0)
select max(CE_Issuedate)
from t_Certificate
where EXISTS (select * from t_item
where IT_rfileID_fk = '1482'
and CE_CertID_pk = IT_rfileID_fk)
如果未找到行,则MAX返回NULL。否则返回CE_Issuedate。