我需要提取上次付款状态超过6个月前帐户记录的代码。但我不太确定为什么我的DateDiff不起作用。如何在SQL Server 2014中获得6个月以上的结果?
我迄今为止代码:
SELECT A.[AccountId]
,[AccountNumber]
,[AccountTypeId]
,[AccountStatusId]
,[CurrentBalance]
,[PaymentStatusID]
,D.Last_Change
FROM [Account] A
INNER JOIN (
SELECT AccountId
,MAX(Created) Last_Change
FROM PaymentStatusHistory
WHERE ToPaymentStatusID IN (1,2,11)
GROUP BY AccountId
) D
ON A.AccountID = D.AccountId
WHERE PaymentStatusID IN (1,2,11)
AND AccountStatusId IN (1,2)
--AND DATEDIFF (DAY, GETDATE(), D.Last_Change) > 180 --Need THIS line corrected.
ORDER BY CurrentBalance DESC, AccountNumber
你是什么意思“不起作用”?你有错误吗?或者结果与你期望的不同? – cddt