string(817) " FROM tabcontratos C inner join (select *, (CASE WHEN CPF IS NOT NULL THEN CPF ELSE CNPJ END) as CPFCNPJ FROM tabcredor) A on (C.NCredor = A.Idcredor) inner join tabcontratotipo T on (C.NTipo = T.Idcontratotipo) LEFT JOIN (SELECT NContrato FROM tabterceirizados GROUP BY NContrato) E ON(C.IdContratos = e.NContrato) LEFT JOIN (SELECT F.NAgente, F.NContrato from tabcontratosfiscal F inner join tabvereador V ON (F.NAgente = V.IdVereador) GROUP BY F.NContrato) F ON (C.IdContratos = F.NContrato) left join tabsecretarias S on (C.NSec = S.IdSecretarias) WHERE IdContratos > 0 AND C.Site = 'S' AND C.DtDelete IS NULL "