我有一个带有 Union 语句的查询,只是为了检查大小写,但我想在 Where 中实现 CASE,但我是 SQL 的初学者,不知道我该怎么做。
我的查询就像
SELECT TOP 1 EndDate
FROM (
SELECT 1 AS seq,
EndDate,
FROM pipeline_rest_envr_info e
WHERE e.tckt_id = imt.tckt_id
AND stat = 'INPR'
UNION
SELECT TOP 1 2 AS seq,
EndDate,
FROM pipeline_rest_envr_info e
WHERE e.tckt_id = imt.tckt_id
AND stat = 'CMPL'
ORDER BY
enddate DESC
UNION
SELECT TOP 1 3 AS seq,
EndDate,
FROM pipeline_rest_envr_info e
WHERE e.tckt_id = imt.tckt_id
AND stat = 'PLND'
ORDER BY
strt_dt
UNION
SELECT 4 AS seq,
NULL,
FROM pipeline_rest_envr_info e
WHERE e.tckt_id = imt.tckt_id
) aa
ORDER BY
aa.seq