我有这行语法,我需要替换静态日期,以便它只在事务日期计算

时间:2018-05-15 13:54:22

标签: sql tsql sql-server-2016

SUM(CASE 
        WHEN DATEDIFF(d , TransactionDate , '2018/05/09') BETWEEN  100 AND  600 
            THEN (TotalValue-TotalPaidtoDate) 
    end )AS [30DaysAmount]

1 个答案:

答案 0 :(得分:0)

你的意思是今天的约会吗?如果是,请使用getdate()

SUM(CASE WHEN DATEDIFF(day, TransactionDate , GETDATE()) BETWEEN 100 AND 600 
         THEN (TotalValue - TotalPaidtoDate) 
    END) AS [30DaysAmount]

我不确定列名称与期间的501天有什么关系。