Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 将bigint转换为日期_Sql_Sql Server - Fatal编程技术网

Sql 将bigint转换为日期

Sql 将bigint转换为日期,sql,sql-server,Sql,Sql Server,我有两个日期,我计算如下: CASE WHEN FinalApprovalDt is not null and mf.IncomingTocontrol = 1 THEN DATEDIFF ( SECOND , ManualDecisionDt , lastChangesByAgentDt) END AS M_ttp CASE WHEN FinalApprovalDt is not null and mf.IncomingTocontrol = 0 and ContractPayoutAmt

我有两个日期,我计算如下:

CASE WHEN FinalApprovalDt is not null and mf.IncomingTocontrol = 1 THEN  DATEDIFF ( SECOND , ManualDecisionDt , lastChangesByAgentDt) END AS M_ttp
CASE WHEN FinalApprovalDt is not null and mf.IncomingTocontrol = 0 and ContractPayoutAmt > 0 THEN  DATEDIFF ( SECOND , SystemDecisionDt , lastChangesByAgentDt) END AS A_ttp
我需要在秒内得到这两个的总量,然后计算平均值,但当:

            (Case When FinalApprovalDt is not null and mf.IncomingTocontrol = 1 and ContractPayoutAmt > 0 then  DATEDIFF ( SECOND , ManualDecisionDt , lastChangesByAgentDt) End +
            Case When FinalApprovalDt is not null and mf.IncomingTocontrol = 0 and ContractPayoutAmt > 0 then  DATEDIFF ( SECOND , SystemDecisionDt , lastChangesByAgentDt) End ) As Total_TTP,

有什么问题吗?

在该查询中有两个相互矛盾的情况,当条件不满足时,您不处理这些情况。基于
mf.IncomingTocontrol
第一种或第二种情况都将为NULL,NULL+任何内容都始终为NULL

您应该在每种情况下放置ELSE块:

(
 Case When FinalApprovalDt is not null and mf.IncomingTocontrol = 1 and ContractPayoutAmt > 0 
 then  DATEDIFF ( SECOND , ManualDecisionDt , lastChangesByAgentDt) 
 ELSE 0 End 
 +
 Case When FinalApprovalDt is not null and mf.IncomingTocontrol = 0 and ContractPayoutAmt > 0 
 then  DATEDIFF ( SECOND , SystemDecisionDt , lastChangesByAgentDt) 
 ELSE 0 End 
) As Total_TTP,
如果为NULL,则使用COALESCE对值进行换行

(
 COALESCE(Case When FinalApprovalDt is not null and mf.IncomingTocontrol = 1 and ContractPayoutAmt > 0 
 then  DATEDIFF ( SECOND , ManualDecisionDt , lastChangesByAgentDt) End, 0) 
 +
 COALESCE(Case When FinalApprovalDt is not null and mf.IncomingTocontrol = 0 and ContractPayoutAmt > 0 
 then  DATEDIFF ( SECOND , SystemDecisionDt , lastChangesByAgentDt) End, 0)
) As Total_TTP,

编辑您的问题并提供示例数据和所需结果。您可能缺少一两个
ELSE 0
<代码>x时的情况,然后。。。当
x
为非真时,END为
NULL
,向任何内容添加
NULL
NULL