我需要提取上次付款狀態超過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