如何在不使用IsNULL
的情况下编写以下语句?
Case
When (IsNull(Email_Ind, '') != 'N'
then 'e'
else 'n'
end
这会得到正确的结果吗?
Case
When Email_Ind != 'N' and Email_Ind is not null
then 'e'
else 'n'
end
您的case语句看起来不错。这只是一个如何写的偏好问题。对我来说,这更容易理解,但我确信情况并非如此。
Case When Email_Ind != 'N' or Email_Ind is null then 'e' else 'n' end
对这类事情使用EXCEPT和INTERSECT:
select case when (select Email_Ind intersect select 'Y') = 1 then 'E' else 'N' end
如@ypercube所建议ᵀᴹ,这也会起作用(并且可能是陈述查询的更具语义的方式):
select case when exists (select Email_Ind intersect select 'Y') then 'E' else 'N' end