如何使用case语句在T-SQL中进行日期比较(>或

时间:2022-05-07 09:10:56

I'm getting an error on the greater than operator in the case statement. What am I missing here?

我在case语句中遇到了大于运算符的错误。我在这里想念的是什么?

DECLARE @ODS_LOAN_MAXDATE DATE, @MAX_MAINTENANCE DATE, @MAX_TRANS DATE, @ODS_LOAN_Count int 

SELECT @MAX_MAINTENANCE = MAX(DATE_MAINTENANCE_LAST) FROM FISERV_ODS..LOAN_MASTER_FILE
SELECT @MAX_TRANS = MAX(DATE_TRANS_LAST) FROM FISERV_ODS..LOAN_MASTER_FILE

SELECT CASE @ODS_LOAN_MAXDATE
    WHEN @MAX_MAINTENANCE > @MAX_TRANS
        THEN @MAX_MAINTENANCE
    ELSE @MAX_TRANS 
END 
FROM FISERV_ODS..LOAN_MASTER_FILE

1 个解决方案

#1


3  

The syntax should be:

语法应该是:

SELECT CASE WHEN @MAX_MAINTENANCE > @MAX_TRANS
        THEN @MAX_MAINTENANCE
    ELSE @MAX_TRANS 
END 

#1


3  

The syntax should be:

语法应该是:

SELECT CASE WHEN @MAX_MAINTENANCE > @MAX_TRANS
        THEN @MAX_MAINTENANCE
    ELSE @MAX_TRANS 
END