我编写了以下TSQL查询,并在Microsoft Report Builder中运行它。我的问题是一部分工作不正常。任何信息都会非常有用。感谢。
这是我遇到问题的部分。由于某种原因,它找不到具有NULL关闭日期的贷款。例如,我正在测试的帐户有一个未结贷款,但当我收到1时,它返回的值是0。有人看到我可能遗漏的东西吗?
(SELECT COUNT(*) -- Check if there are no open loans
FROM arcu.vwARCULoan AS L
WHERE A.ACCOUNTNUMBER=L.AccountNumber AND
L.ProcessDate = (SELECT ProcessDate FROM ufnARCUGetLatestProcessDate()) AND
L.LoanCloseDate IS NOT NULL)=0 AND -- END Check if there are no open loans
以下是整个查询。
SELECT
A.ACCOUNTNUMBER AS 'Account Number'
,A.AccountBranch AS 'Branch Number'
,A.AccountOpenDate AS 'Account Open Date'
,A.AccountActivityDate AS 'Last Activity Date'
,N.NameFirst+' '+N.NameLast AS 'Member Name'
FROM
arcu.vwARCUAccount AS A
LEFT OUTER JOIN arcu.vwARCUName AS N
ON A.ACCOUNTNUMBER = N.AccountNumber
WHERE
A.ProcessDate = (SELECT ProcessDate FROM ufnARCUGetLatestProcessDate()) AND
A.AccountCloseDate IS NULL AND
A.AccountOpenDate>DATEADD(DAY,-30,A.AccountOpenDate) AND
N.NameType=0 AND
N.ProcessDate = (SELECT ProcessDate FROM ufnARCUGetLatestProcessDate()) AND
(SELECT SUM(S.ShareBalance) -- Check if all shares are zero
FROM arcu.vwARCUShare AS S
WHERE A.ACCOUNTNUMBER=S.AccountNumber AND
S.ProcessDate = (SELECT ProcessDate FROM ufnARCUGetLatestProcessDate()) AND
A.ProcessDate = (SELECT ProcessDate FROM ufnARCUGetLatestProcessDate()))=0 AND -- END Check if all shares are zero
(SELECT COUNT(*) -- Check if there are no open loans
FROM arcu.vwARCULoan AS L
WHERE A.ACCOUNTNUMBER=L.AccountNumber AND
L.ProcessDate = (SELECT ProcessDate FROM ufnARCUGetLatestProcessDate()) AND
A.ProcessDate = (SELECT ProcessDate FROM ufnARCUGetLatestProcessDate()) AND
L.LoanCloseDate IS NOT NULL)=0 AND -- END Check if there are no open loans
(SELECT COUNT(*) --Check if tracking records exist
FROM arcu.vwARCULoanTracking AS T
WHERE A.ACCOUNTNUMBER=T.AccountNumber AND
T.ProcessDate = (SELECT ProcessDate FROM ufnARCUGetLatestProcessDate()) AND
A.ProcessDate = (SELECT ProcessDate FROM ufnARCUGetLatestProcessDate()) AND
T.LoanTrackingType IN(@TRACKINGTYPES) )=0 AND --END Check if tracking records exist
(SELECT COUNT(*)
FROM arcu.vwARCUInventory AS I
WHERE A.ACCOUNTNUMBER=I.InventoryAccountNumber AND
I.ProcessDate = (SELECT ProcessDate FROM ufnARCUGetLatestProcessDate()) AND
A.ProcessDate = (SELECT ProcessDate FROM ufnARCUGetLatestProcessDate()) AND
I.InventoryStatus=2 AND
I.InventoryType IN (@INVENTORYTYPE))=0
ORDER BY A.ACCOUNTNUMBER
答案 0 :(得分:0)
我假设如果贷款仍然“开放”,那么L.LoanCloseDate将为空。
在这种情况下,查询的问题是
L.LoanCloseDate IS NOT NULL
此标准表示您只计算已关闭贷款,即贷款在LoanClosedDate中的值。你似乎需要的是与此相反的,即公开贷款。所以你可能只需要将这个标准改为
L.LoanCloseDate IS NULL
以便您计算开启贷款。