case语句返回的是0而不是空字符串

hk8txs48  于 2021-07-24  发布在  Java
关注(0)|答案(1)|浏览(436)

我有以下案例陈述;

case when (
    CASE 
    WHEN datediff(year,view_3.[PERSON BIRTH DATE], @ReportPeriodStartDate)  >= 19 AND view_3.[NI NUMBER] IS NOT NULL 
        THEN '' ELSE view_3.[NI NUMBER]  END ) = 0 then '' else view_3.[NI NUMBER] END AS [NI NUMBER],

我想把它还回去

Birthddate  NI Number   

14/04/2012  9000
06/05/2020  2000
01/01/2001
22/12/1998

但我得到的结果是;

Birthddate  NI Number   

14/04/2012  9000
06/05/2020  2000
01/01/2001  0
22/12/1998  0

我不要零,我要空字符串。

soat7uwm

soat7uwm1#

您想要返回一个字符串,因此需要将 else :

else cast(view_3.[NI NUMBER] as varchar(255))

相关问题