estoy tratando de hacer un query que me de todas las descripciones de las facruras de proveedores y empate con su asiento de diario.
El problema que tengo es que si hago una consulta a la tabla OJDT me lanza una cantidad diferente con las condiciones del que el formato de código sea mayo a 600000000 y menos a 700000000, entonces cuando meto las facturas de compra no me da lo mismo, si alguien me puede
SELECT T0.[TransId], CASE WHEN T0.Transtype=18 THEN 'FP' END AS 'Operacion',T0.[RefDate]as 'Fecha Poliza', t0.number as '# Poliza', T0.[BaseRef] as '# Docto SAP',T4.[AcctName] AS 'Cuenta', T4.[FormatCode] as '# Cuenta', T3.[lineTotal],case when t0.transtype=18 then 0 end,T2.[Comments], T3.[LineVat],T3.[Dscription] FROM [dbo].[OJDT] T0 INNER JOIN [dbo].[OPCH] T2 ON T0.TransId = T2.TransId INNER JOIN PCH1 T3 ON T2.DocEntry = T3.DocEntry INNER JOIN OACT T4 ON T3.AcctCode = T4.AcctCode WHERE t0.refdate>='[%0]' and t0.refdate<='[%1]' and (t4.formatcode>'599999999' AND T4.FORMATCODE<'700000000') and t0.transtype=18 union all SELECT T0.[TransId], case when t0.transtype=13 then 'FC' WHEN t0.transtype=14 THEN 'NC clientes' WHEN T0.TRANSTYPE=18 THEN 'FP' WHEN T0.TRANSTYPE=19 THEN 'NC Prov' WHEN T0.TRANSTYPE=24 THEN 'PR' WHEN t0.transtype=25 THEN 'Dep.' when t0.transtype=30 THEN 'AS' WHEN t0.transtype=321 THEN 'GC ID' When t0.transtype=46 THEN 'PE' WHEN t0.transtype=59 THEN 'EM' when t0.transtype=60 THEN 'SM' END AS 'Operacion' , T0.[RefDate] as 'Fecha Poliza',t0.number as '# Poliza', t0.baseref as '# Docto SAP', T2.[AcctName] AS 'Cuenta', T2.[FormatCode] as '# Cuenta', T1.[Debit], T1.[Credit], T1.[LineMemo],T1.[TotalVat] ,t1.ref3line FROM [dbo].[OJDT] T0 INNER JOIN [dbo].[JDT1] T1 ON T0.TransId = T1.TransId INNER JOIN [dbo].[OACT] T2 ON T1.Account = T2.AcctCode WHERE t0.refdate>='[%0]' and t0.refdate<='[%1]' and (t2.formatcode>'599999999' AND T2.FORMATCODE<'700000000') and t0.transtype<>18