我编写了以下 TSQL 查询并在 Microsoft Report Builder 中运行它。我的问题是一部分工作不正常。任何信息都会非常有帮助。谢谢。
- 注意 - (SELECT ProcessDate FROM ufnARCUGetLatestProcessDate()) 返回运行查询的日期。这是我们的标准功能之一。
这是我遇到问题的部分。由于某种原因,它没有找到关闭日期为 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