podrian ayudarme, no se me ocurre como eliminar los registros duplicados de esta consulta:
SELECT DISTINCT
VendorName
, Vendor
, Reference
, DocumentNumber
, ClearingDocument
, DocumentDate
, ClearingDate
, '' AS 'TDP'
, '' AS 'SAP'
, DocumentCurrency
, 0 AS 'WF'
, CASE
WHEN DocumentCurrency = 'MXN' THEN AmountInDocCurr
ELSE 0
END as 'MXN'
, CASE
WHEN DocumentCurrency = 'USD' THEN AmountInDocCurr
ELSE 0
END as 'USD'
, AmountInDocCurr
, Round(VATAmount / 0.16, 2) AS 'Base16'
, Round(NetAmount - Round(VATAmount / 0.16, 2), 2) AS 'Base0'
, 0 AS 'Base8'
, 0 AS 'Exento'
, Round(VATAmount, 2) AS 'IVA16'
, 0 AS 'IVA8'
, WithholdingTaxAmnt AS 'IVARet'
, 0 AS 'ISRRet'
, AmountInDocCurr AS 'TotalFactura'
, CASE
WHEN DocumentCurrency = 'USD' THEN dbo.sp_getTCTypes3
( ClearingDate )
ELSE 1
END as 'TC'
, TextField
FROM Tbl_MXInvoices
WHERE Month(ClearingDate) = 8 AND Year(ClearingDate) = 2021;