Buenas amigos
Estoy contruyendo un query para tener un balance de comprobación (trial balance) y despues pasarlo a crystal report, tengo que presentarla a la auditoria externa un balance de comprobación que tenga las siguientes columnas:
Numero de cuenta contable
Nombre de la cuenta contable
Saldo Inicial de la cuenta al inciar el año
Débitos del año
Créditos del año
Saldo final de la cuenta al finalizar el año
Para lo cual construí este query, lo copie al query manager de SAP B1, y me da el siguiente error
1). [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]Must specify table to select from.
2). [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]Statement ‘Acuerdo global’ (OOAT) (s) could not be prepared.
A continuación el query,
declare @dbeger datetime
set @dbeger = ‘[%0]’
declare @dender datetime
set @dender = ‘[%1]’
declare @dbegbs datetime
set @dbegbs = (’[%0]’ - 1)
declare @dendbs datetime
set @dendbs = ‘[%1]’
SELECT
T0.AcctCode AS “Cuenta”,
T0.acctName AS “Nombre”,
( SELECT ISNULL(SUM(B.Debit - B.Credit),0) FROM OJDT A INNER JOIN JDT1 B ON A.TransId = B.TransId WHERE B.Account = T0.AcctCode and A.RefDate <= @dbegbs ) AS “Saldo Inicial”,
( SELECT ISNULL(SUM(B.Debit),0) FROM OJDT A INNER JOIN JDT1 B ON A.TransId = B.TransId WHERE B.Account = T0.AcctCode AND A.RefDate >= @dbeger AND A.RefDate <= @dender ) AS “Débito”,
( SELECT ISNULL(SUM(B.Credit),0) FROM OJDT A INNER JOIN JDT1 B ON A.TransId = B.TransId WHERE B.Account = T0.AcctCode AND A.RefDate >= @dbeger AND A.RefDate <= @dender ) AS “Crédito”,
( SELECT ISNULL(SUM(B.Debit - B.Credit),0) FROM OJDT A INNER JOIN JDT1 B ON A.TransId = B.TransId WHERE B.Account = T0.AcctCode and A.RefDate <= @dendbs ) AS “Saldo Final”
FROM OACT T0
WHERE T0.Postable = ‘Y’ AND T0.GroupMask IN (1,2,3)
UNION ALL
SELECT
T0.AcctCode AS “Cuenta”,
T0.acctName AS “Nombre”,
‘0’ AS “Saldo Inicial”,
( SELECT ISNULL(SUM(B.Debit),0) FROM OJDT A INNER JOIN JDT1 B ON A.TransId = B.TransId WHERE B.Account = T0.AcctCode AND A.RefDate >= @dbeger AND A.RefDate <= @dender AND A.TransType <> -3 ) AS “Débito”,
( SELECT ISNULL(SUM(B.Credit),0) FROM OJDT A INNER JOIN JDT1 B ON A.TransId = B.TransId WHEREB.Account = T0.AcctCode AND A.RefDate >= @dbeger AND A.RefDate <= @dender AND A.TransType <> -3 ) AS “Crédito”,
( SELECT ISNULL(SUM(B.Debit - B.Credit),0) FROM OJDT A INNER JOIN JDT1 B ON A.TransId = B.TransId WHERE B.Account = T0.AcctCode AND A.RefDate >= @dbeger AND A.RefDate <= @dender AND A.TransType <> -3 ) AS “Saldo_Final”
FROM OACT T0
WHERE T0.Postable = ‘Y’ AND T0.GroupMask IN (4,5,6,7,8,9,10)
ORDER BY T0.AcctCode
Agradecería si me alguno me puede indicar que estoy haciendo mal.
Saludos