select a.sDoc,     a.jTipo,     a.pCedente,     a.pSacado,     a.tEmissao,     a.tEnvCnab,     a.tEnvBol,     a.tRestr,     a.tLibRestr,     a.pCapa,     a.lCapa,     a.pTOper,     a.iPrest,     a.pContr,     a.iNrPrest,      a.tAgend,     a.jOri,        a.iIde_nNF,     b.sCoringa  sCedente,     b.sCNPJ   sCNPJCedente,     b.sCPF    sCPFCedente,     b.sAgencia  sAgenciaCedente,     b.lAgencia  lAgenciaCedente,     c.sCoringa  sSacado,     c.sCNPJ   sCNPJSacado,     c.sCPF    sCPFSacado,      c.sAgencia  sAgenciaSacado,     c.lAgencia  lAgenciaSacado,     a.tVenc,     a.tVenc0,     a.nVenc,     a.tCanc   dCanc,     a.tPgmto,     a.nPgmto,     a.lPrevisao,     a.pOrdem,     a.pNFe,     a.pPreNF,     a.pTransf,     d.sDescricao sTOper,     d.sCodigo  sCodTOper,     g.sCC    sCC,     g.sDac    sDac,     h.sAgencia  sAgeNr,     h.sCoringa  sAge,     h.pBanco   pBanco,     h.fBanco   fBanco,     i.sCodigo  sCodBanco,     i.sDescricao sDesBanco,     j.tConf   tOrdemConf,     a.pTipoCob,     e.sDescricao sTipoCob,     e.sCodigo   sCodTipoCob,     a.pTFinOrig,     a.lOrcNA,     a.pPId  from FIN_Titulos a    join CUP              b on a.pCedente  = b.pPId and b.iVer = b.iVAt              join CUP              c on a.pSacado   = c.pPId and c.iVer = c.iVAt              join FIN_Detalhamento_Desc_Acresc  f on f.pFin    = a.pPId and f.iVer = f.iVAt            left join TOper       d on a.pTOper  = d.pPId and d.iVer = d.iVAt            left join CC        g on a.pCC   = g.pPid and g.iVer = g.iVAt            left join CUP        h on g.pAgencia = h.pPid and h.iVer = h.iVAt            left join Banco       i on h.pBanco  = i.pPid and i.iVer = i.iVAt            left join Ordens      j on a.pOrdem  = j.pPId and j.iVer = j.iVAt and j.tCanc is null and j.tLibCom is not null and j.lExc=0            left join Tipo_Cobrancas  e on a.pTipoCob = e.pPId and e.iVer = e.iVAt  where a.iVer = a.iVAt   and a.lExc   = 0   and f.pVerbaPrest = 3816215  group by a.sDoc,      a.jTipo,      a.pCedente,      a.pSacado,      a.tEmissao,      a.tEnvCnab,      a.tEnvBol,      a.tRestr,      a.tLibRestr,      a.pCapa,      a.lCapa,      a.pTOper,      a.iPrest,      a.pContr,      a.iNrPrest,       a.tAgend,      a.jOri,         a.iIde_nNF,      b.sCoringa,      b.sCNPJ,      b.sCPF,      b.sAgencia,      b.lAgencia,      c.sCoringa,      c.sCNPJ,      c.sCPF,       c.sAgencia,      c.lAgencia,      a.tVenc,      a.tVenc0,      a.nVenc,      a.tCanc,      a.tPgmto,      a.nPgmto,      a.lPrevisao,      a.pOrdem,      a.pNFe,      a.pPreNF,      a.pTransf,      d.sDescricao,      d.sCodigo,      g.sCC,      g.sDac,      h.sAgencia,      h.sCoringa,      h.pBanco,      h.fBanco,      i.sCodigo,      i.sDescricao,      j.tConf,      a.pTipoCob,      e.sDescricao,      e.sCodigo,      a.pTFinOrig,      a.lOrcNA,      a.pPId  order by a.iIde_nNF desc