Buenos días
Me podrían ayudar con esta duda, tengo un reporte de antigüedad de saldos del cliente EN SAP Business One que realice con ayuda de un query de un foro, donde involucro facturas, notas de crédito pagos recibidos, pagos efectuados , la cuestión es que si lo corro al día y lo comparo con el de SAP si concuerda, pero no he logrado que si se corre a una fecha anterior de el mismo resultado que el de SAP
Anexo pantalla
/* DEC*/ SELECT T6.CompnyName, T6.PrintHeadr, T6.FreeZoneNo, T0.CardCode, T0.CardName, T1.TransId 'Asiento', T4.DocSeries, T4.TransType,
T4.BaseRef 'Doc Interno', T4.RefDate, T4.DueDate, CASE WHEN T3.DebHab = 'D' THEN (T1.Debit - T1.Credit) WHEN T3.DebHab = 'C' THEN (T1.Debit - T1.Credit)
ELSE (T1.Debit - T1.Credit) END 'Saldo', CASE T1.TransType WHEN '13' THEN
(SELECT Y.Comments
FROM DEC.DBO.OINV Y
WHERE Y.TransId = T1.TransId) WHEN '14' THEN
(SELECT Y.Comments
FROM DEC.DBO.ORIN Y
WHERE Y.TransId = T1.TransId) ELSE T1.LineMemo END 'Comentarios', CASE T1.TransType WHEN '13' THEN
(SELECT Y.DocStatus
FROM DEC.DBO.OINV Y
WHERE Y.TransId = T1.TransId) WHEN '14' THEN
(SELECT Y.DocStatus
FROM DEC.DBO.ORIN Y
WHERE Y.TransId = T1.TransId) WHEN '24' THEN
(SELECT Y.PayNoDoc
FROM DEC.DBO.ORCT Y
WHERE Y.TransId = T1.TransId) WHEN '46' THEN
(SELECT Y.PayNoDoc
FROM DEC.DBO.OVPM Y
WHERE Y.TransId = T1.TransId) WHEN '30' THEN
(SELECT Y.BtfStatus
FROM DEC.DBO.OJDT Y
WHERE Y.TransId = T1.TransId) END 'DocStatus', CASE T1.TransType WHEN '24' THEN
(SELECT Y.NoDocSum
FROM DEC.DBO.ORCT Y
WHERE Y.TransId = T1.TransId) WHEN '46' THEN
(SELECT Y.NoDocSum
FROM DEC.DBO.OVPM Y
WHERE Y.TransId = T1.TransId) END 'Saldo2', CASE T1.TransType WHEN '24' THEN
(SELECT Y.OpenBal
FROM DEC.DBO.ORCT Y
WHERE Y.TransId = T1.TransId) WHEN '46' THEN
(SELECT Y.OpenBal
FROM DEC.DBO.OVPM Y
WHERE Y.TransId = T1.TransId) END 'Saldo3', CASE T1.TransType WHEN '13' THEN
(SELECT Y.PaidToDate
FROM DEC.DBO.OINV Y
WHERE Y.TransId = T1.TransId) WHEN '14' THEN
(SELECT Y.PaidToDate
FROM DEC.DBO.ORIN Y
WHERE Y.TransId = T1.TransId) END 'Pagado'
FROM DEC.DBO.OADM T6, DEC.DBO.OCRD T0 INNER JOIN
DEC.DBO.JDT1 T1 ON T1.ShortName = T0.CardCode INNER JOIN
DEC.DBO.OACT T2 ON T2.AcctCode = T1.Account INNER JOIN
DEC.DBO.OJDT T4 ON T4.TransId = T1.TransId LEFT JOIN
(SELECT X0.ShortName 'SN', X0.TransId 'TransId', SUM(X0.ReconSum) 'ReconSum', X0.IsCredit 'DebHab', X0.TransRowId 'Linea'
FROM DEC.DBO.ITR1 X0 INNER JOIN
DEC.DBO.OITR X1 ON X1.ReconNum = X0.ReconNum
WHERE X1.CancelAbs = ''
GROUP BY X0.ShortName, X0.TransId, X0.IsCredit, X0.TransRowId) T3 ON T3.TransId = T1.TransId AND T3.SN = T1.ShortName AND T3.Linea = T1.Line_ID
WHERE T0.CardType = 'C' AND (T2.AcctCode = '_SYS00000000090' OR
T2.AcctCode = '_SYS00000000091') AND (CASE WHEN T3.DebHab = 'D' THEN (T1.Debit - T1.Credit) WHEN T3.DebHab = 'C' THEN (T1.Debit - T1.Credit)
ELSE (T1.Debit - T1.Credit) END) != '0'
Gracias