Hello:
I have spent time creating a column in an Excel spreadsheet that uses Excel's Microsoft Query technology to pull Open A/R data for our previous fiscal year ending 09/30/2015.
Essentially, this T-SQL query that I wrote is the beginnings of a query that I'm working on to create GP's Receivables Historical Aged Trial Balance (HATB) in Excel through Microsoft Query.
I'm comparing the total of my results with GP's Receivables HATB, aged as of 09/30/2015. I'm conducting this comparison, one bucket at a time.
In my query excerpt below, I'm trying to pull data for our "Current" bucket which is simply "0 days to 0 days".
In GP's Receivables HATB, the figure for "Current" as of 09/30/2015 is being displayed as about $42.6 million dollars. My query derives about $41.7 million dollars. So, my query is off by a little less than $1 million.
I've researched, tested, and done everything that I know to do to edit and fix my query, for the "Current" bucket.
But, I've been unsuccessful in figuring out why I'm off.
The GP Receivables HATB report options is not excluding Unposted Applied Credit Amounts. But, even if I check the box to exclude those, the amounts in the HATB remain the same. Otherwise, "Zero Balance", "Fully Paid Documents", and "No Activity" are excluded.
I don't expect anyone to rewrite my query, for me. But, can someone please review my query below for the "Current" bucket and perhaps give me at least some ideas or hints as to what else I can be doing to correctly "adjust" this programming?
I realize that I'm not pulling any data from either the RM20201 table or the historical RM tables. We don't generally move receivables data to history. For the most part, it's all in open. Perhaps, though. I should be pulling data from RM20201. But, so far, I have not seen a reason to do so.
Thanks, so much! This is much appreciated!
John
DECLARE @AGE DATETIME
SET @AGE = '2015-09-30 00:00:00.000'
select RM20101.CUSTNMBR as [CUSTOMER ID], RM00101.CUSTNAME AS [NAME], RM00101.PYMTRMID AS [PAYMENT TERMS],
SUM(
(CASE WHEN DATEDIFF(dd, RM20101.DOCDATE, @AGE) <= 0
and RM20101.RMDTYPAL > 6
THEN RM20101.CURTRXAM * - 1
WHEN DATEDIFF(dd, RM20101.DUEDATE, @AGE) <= 0
and RM20101.RMDTYPAL < 7
THEN RM20101.CURTRXAM ELSE 0 END)) as [Current]
from RM20101
INNER JOIN RM00101 on RM20101.CUSTNMBR = RM00101.CUSTNMBR
LEFT OUTER JOIN CN00500 ON RM20101.CUSTNMBR = CN00500.CUSTNMBR
WHERE (RM20101.VOIDSTTS = 0)
GROUP BY RM20101.CUSTNMBR, RM00101.CUSTNAME, RM00101.PYMTRMID, CN00500.CRDTMGR, RM00101.COMMENT1, RM00101.COMMENT2
HAVING SUM(
(CASE WHEN DATEDIFF(dd, RM20101.DOCDATE, @AGE) <= 0
and RM20101.RMDTYPAL > 6
THEN RM20101.CURTRXAM * - 1
WHEN DATEDIFF(dd, RM20101.DUEDATE, @AGE) <= 0
and RM20101.RMDTYPAL < 7
THEN RM20101.CURTRXAM ELSE 0 END))
<> 0
ORDER BY RM20101.CUSTNMBR