Buenas tardes colegas en el trabajo donde estoy me colocaron a modificar un query de SQL SERVER donde debo traer un campo llamado ATR_DEPOSIT de una tabla llamada ACCOUNTING_TRANSACTION, el campo PRIMARY KEY de esta tabla es ATR_IDENTITY_CODE, suena muy sencillo lo se, pero al intentar traerlo me salen diferentes errores dependiendo donde coloque ACCOUNTING_TRANSACTION.ATR_DEPOSIT Alguno sabe como solucionar esto ? de ante mano muchas Gracias.
Este es el query que funciona muy bien sin yo intentar traer dicho campo:
SELECT 0 COMMENTS,'PREVIOUS BALANCE' AS ACO_NAME,1 AS ATR_IDENTITY_CODE,
'PREVIOUS BALANCE' AS ATR_DESCRIPTION, '' AS BAN_NAME, '' AS BAC_ACCOUNT_NUMBER,
9834.0000 AS ATR_DEBIT, 5468.0000 AS ATR_CREDIT,
CONVERT(DATETIME,'4/6/2018') AS ATR_DATETIME,
'' AS ATR_DEPOSIT_IMAGE_PATH,
11 AS ATR_ACCOUNTING_CONCEPT, 4366.0000 AS TOTAL, CONVERT(DATETIME,'4/6/2018') AS ATR_DATE_POSTED,
'NO' AS AGING_STATUS , '0' as ATR_DEBIT_NATIONAL_CURRENCY , '0' as ATR_CREDIT_NATIONAL_CURRENCY,
'0' AS BALANCE_NATIONAL_CURRENCY
UNION SELECT isnull(
(SELECT COUNT (ATM_ACCOUNTING) FROM ACCOUNTING_TRANSACTION_MESSAGE
WHERE ATM_ACCOUNTING = ATR_IDENTITY_CODE ) ,0)
COMMENTS , ACCOUNTING_CONCEPT.ACO_NAME AS ACO_NAME,
ACCOUNTING_TRANSACTION.ATR_IDENTITY_CODE AS ATR_IDENTITY_CODE,
ACCOUNTING_TRANSACTION.ATR_DESCRIPTION AS ATR_DESCRIPTION,
BANK.BAN_NAME AS BAN_NAME,
BANK_ACCOUNT.BAC_ACCOUNT_NUMBER AS BAC_ACCOUNT_NUMBER,
ATR_DEBIT, ATR_CREDIT, ATR_DATETIME,ATR_DEPOSIT_IMAGE_PATH, ATR_ACCOUNTING_CONCEPT,
ISNULL(
(SELECT SUM(A.ATR_DEBIT - A.ATR_CREDIT)
FROM ACCOUNTING_TRANSACTION A
WHERE A.ATR_ACCOUNTING_GROUP = 'O461' AND A.ATR_DATETIME <= ACCOUNTING_TRANSACTION.ATR_DATETIME
AND A.ATR_ACCOUNTING_CONCEPT <> 11 AND ATR_STATUS = 'A'),0) AS TOTAL,
ATR_DATE_POSTED,
IIF(ATR_CREDIT_STATUS IS NULL AND ATR_DEBIT_STATUS IS NULL, 'NO', 'YES') AS AGING_STATUS,
ATR_DEBIT_NATIONAL_CURRENCY, ATR_CREDIT_NATIONAL_CURRENCY ,
(ATR_DEBIT_NATIONAL_CURRENCY - ATR_CREDIT_NATIONAL_CURRENCY) AS BALANCE_NATIONAL_CURRENCY
FROM ACCOUNTING_TRANSACTION
INNER JOIN ACCOUNTING_CONCEPT
ON ACCOUNTING_TRANSACTION.ATR_ACCOUNTING_CONCEPT = ACCOUNTING_CONCEPT.ACO_IDENTITY_CODE
LEFT OUTER JOIN BANK
ON ACCOUNTING_TRANSACTION.ATR_BANK = BANK.BAN_CODE
LEFT OUTER JOIN BANK_ACCOUNT
ON ACCOUNTING_TRANSACTION.ATR_BANK_ACCOUNT = BANK_ACCOUNT.BAC_CODE
WHERE ATR_ACCOUNTING_GROUP = 'O461' AND ATR_STATUS = 'A'
AND ATR_DATETIME >= CAST('4/6/2018 00:00:00.001' AS DATETIME)
AND ATR_DATETIME <= CAST('4/13/2018 23:59:59.999' AS DATETIME)ORDER BY ATR_DATETIME
UNION
... algo así:... '0' AS BALANCE_NATIONAL_CURRENCY, ACCOUNTING_TRANSACTION.ATR_DEPOSIT UNION SELECT isnull( ...