Hola… ahí va…
SELECT a.N_Comprobante as 'Nº Comprobante',FORMAT (a.Fecha,'dd/MM/yyyy') as 'Fecha', a.Nombre_del_Cliente as 'Nombre del Cliente', a.CUIT as 'CUIT',
sum(a.Importe_Gravado) AS 'Importe gravado', sum(a.Importe_No_Gravado) as 'Importe No Gravado', sum (a.IVA_21) as 'IVA %21', SUM (a.IVA_27) AS 'IVA %27',
SUM (a.IVA_105S) AS 'IVA %10,5',SUM(a.Percep_IVA) as 'Percep. IIBB',sum (a.Total) as 'Total'
FROM osta inner join (SELECT CONCAT ('FC',T0.Letter,RIGHT(CONCAT('0000', CAST(T0.PTICode as varchar)), 4),RIGHT(CONCAT('00000000', CAST(T0.FolNumFrom as varchar)), 8)) as 'N_Comprobante',
T0.TaxDate as 'Fecha',
T0.CardName as 'Nombre_del_Cliente', t0.DocEntry,
FORMAT (CAST (T0.LicTradNum AS NUMERIC), '##-########-#') as 'CUIT',
CASE WHEN T1.VatPrcnt > 0 THEN sum(T1.LineTotal) else 0 END as 'Importe_Gravado',
CASE WHEN T1.VatPrcnt = 0 THEN sum(T1.LineTotal) else 0 END as 'Importe_No_Gravado',
CASE WHEN T2.code = 'IVA_21' OR T2.code ='IVA_21S' OR T2.code ='IVA_21BU' THEN SUM(T1.VatSum) else 0 END as 'IVA_21',
CASE WHEN (T2.code = 'IVA10,5S' or T2.code = 'IVA10.5') THEN SUM(T1.VatSum) else 0 END as 'IVA_105S',
CASE WHEN T2.code = 'IVA_27' THEN SUM(T1.VatSum) else 0 END as 'IVA_27',
case when 0 < 1 then 0 end as 'Percep_IVA',
(sum (T1.LineTotal) + sum (T1.VatSum)) as 'Total',
T1.taxcode
FROM OINV T0 INNER JOIN INV1 T1 ON T0.[DocEntry] = T1.[DocEntry]
LEFT JOIN OSTA T2 ON T1.TaxCode = T2.Code
WHERE T0.Canceled = 'N' and T0.TaxDate BETWEEN [%0] AND [%1]
GROUP BY T0.TaxDate, T0.[Letter], T0.FolNumFrom, T0.[LicTradNum],T0.[PTICode], T0.[CardName], T1.[VatPrcnt], T1.DocEntry, T2.Code, T0.DocEntry, T1.taxcode) A on a.TaxCode = OSTA.Code
GROUP BY a.Fecha, a.N_Comprobante,a.Nombre_del_Cliente, a.CUIT