Spotfire中的Datediff为null

问题描述 投票:0回答:1

我想计算两个日期之间的差值,但是如果 "结束日期 "有空,比如第二行和第四行,那么我想放入 "今天"......数据表是这样的。

Hire Date             Term Date = "end date"          
01/01/2019            05/01/2020
05/04/2018            
09/17/2019            03/18/2020
10/19/2018

我是觉得这样的东西可以用,但不是......

If([Term Date]<>NULL THEN DateDiff("year",[Hire Date],[Term Date])
ELSE  DateDiff("year",[Hire Date],Today())
END 

先谢谢你了!

spotfire datediff calc
1个回答
1
投票

你可以使用SN(),就是替代Null。

DateDiff('year',[Hire Date] ,  SN([TermDate],Today() )   )

或者使用case语句而不是IF,因为你的IF语句的格式是不正确的------。If(argument, True, False) 是正确的格式,但在某些时候,案例更容易处理。

Case when [Term Date] is null then DateDiff("year",[Hire Date],Today()) 
else DateDiff("year",[Hire Date],[Term Date]) 
end 
© www.soinside.com 2019 - 2024. All rights reserved.