Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- select (Select est.NOME from estados est where est.SIGLA = clientes.ESTADO ) as nomeestado
- , (Select est.NOME from estados est where est.SIGLA = clientes.COB_ESTADO ) as cob_nomeestado
- , clientes.cnpj_cpf
- , CODIGO, NOME, FANTASIA, ENDERECO, BAIRRO, DOC_PESSOA_ESTRANGEIRA, TIPO_PESSOA
- , CIDADE, ESTADO, PAIS, CEP, FONE
- , FAX, CELULAR, EMAIL, CONTATO, TIPO
- , CGC, INSC, CPF, RG, DATA_CAD
- , ULT_COMPRA, OBS, REPRESENT
- , COMISSAO
- , (select ca.valor
- from clientes_atributo ca
- where ca.id_cliente = clientes.id
- and ca.cod_atributo = :atri_ctrc_icms_aliquota
- ) as aliquota
- , PRACA_PGTO, INSC_MUN, EMPRESA
- , REF, CIDADES_GERAL_ID, COD_IBGE, NUMERO, PAISES_ID
- , (select first 1 cle.endereco from clientes_endereco cle where cle.id_cliente = clientes.id and cle.tipo = 'COBRANCA') as cob_endereco
- , (select first 1 cle.numero from clientes_endereco cle where cle.id_cliente = clientes.id and cle.tipo = 'COBRANCA') as cob_numero
- , (select first 1 cle.complemento from clientes_endereco cle where cle.id_cliente = clientes.id and cle.tipo = 'COBRANCA') as cob_complemento
- , (select first 1 cle.bairro from clientes_endereco cle where cle.id_cliente = clientes.id and cle.tipo = 'COBRANCA') as cob_bairro
- , (select first 1 ci.nome_auxiliar from cidades_geral ci inner join clientes_endereco cle on cle.codigo_cidade = ci.codigo where cle.id_cliente = clientes.id and cle.tipo = 'COBRANCA') as cob_cidade
- , (select first 1 cle.uf from clientes_endereco cle where cle.id_cliente = clientes.id and cle.tipo = 'COBRANCA') as cob_estado
- , (select first 1 cle.cep from clientes_endereco cle where cle.id_cliente = clientes.id and cle.tipo = 'COBRANCA') as cob_cep
- , (select first 1 cle.codigo_cidade from clientes_endereco cle where cle.id_cliente = clientes.id and cle.tipo = 'COBRANCA') as cob_cidades_geral_id
- , (select first 1 ci.cod_ibge from cidades_geral ci inner join clientes_endereco cle on cle.codigo_cidade = ci.codigo where cle.id_cliente = clientes.id and cle.tipo = 'COBRANCA') as cob_cod_ibge
- , DATA_NASC, DADOS_BANCARIOS
- , COMISSAO_CTRCCIF
- , EMAIL2, ID, CODIGO_LOCAL_COBRANCA, ENQUADRAMENTO_CFOP
- , COMPLEMENTO, ID_CIDADES_SETOR, ID_CENTRO_CUSTO, ID_CENTRO_RECEITA
- , (select s.descricao from cidades_setor s where s.id = clientes.id_cidades_setor) as descricao_setor
- , pis_nit, rntrc, inss, rg_uf, rg_orgao_expedidor
- , (select m.id from motoristas m where m.id_cliente = clientes.id) as id_motorista
- , (select m.codigo from motoristas m where m.id_cliente = clientes.id) as codigo_motorista
- , (select first 1 f.codigo from funcionarios f where f.id_cliente = clientes.id order by coalesce(f.data_demissao, '') asc) as codigo_funcionario
- , (select first 1 f.data_demissao from funcionarios f where f.id_cliente = clientes.id order by coalesce(f.data_demissao, '') asc) as data_demissao_funcionario
- , (select p.nome from paises p where p.id = clientes.paises_id) pais_nome
- , (select 'Cadastro vinculado a empresa'
- from empresa emp
- where emp.codigo = empresa
- and coalesce(cgc, '''') = (select saida
- from somentenumeros(emp.cnpj))) as vinculo_clientes_empresa
- , ID_CONDICAO_PAGAMENTO
- , (select p.descricao from condicoes_pagamento p where p.id = clientes.id_condicao_pagamento) as DESCRICAO_CONDICAO_PAGAMENTO
- , (select p.codigo from condicoes_pagamento p where p.id = clientes.id_condicao_pagamento) as CODIGO_CONDICAO_PAGAMENTO
- , (select p.parcelas from condicoes_pagamento p where p.id = clientes.id_condicao_pagamento) as NUM_PARCELAS
- , (select p.intervalo_dias from condicoes_pagamento p where p.id = clientes.id_condicao_pagamento) as INTERVALO_DIAS
- , (select p.dias_vencimento from condicoes_pagamento p where p.id = clientes.id_condicao_pagamento) as VENCIMENTO_1_PARCELA
- , (select fc.codigo from fcen_custo fc where fc.id = clientes.id_centro_custo) as centcusto
- , (select fc.codigo from fcen_custo fc where fc.id = clientes.id_centro_receita) as centreceita
- , id_cliente_pai
- , rg_data_emissao
- , codigo_cidade_naturalidade
- , (select cg.nome || '-' || cg.uf from cidades_geral cg where cg.codigo = clientes.codigo_cidade_naturalidade) as naturalidade
- , sexo
- , (select cg.cod_ibge || cg.dv
- from cidades_geral cg
- where clientes.cidades_geral_id = cg.codigo) as cod_ibge_completo
- , (select count(1) from clientes_modalidade cm where cm.id_cliente = clientes.id and cm.modalidade = :modalidade_cliente) as modalidade_cliente
- , (select count(1) from clientes_modalidade cm where cm.id_cliente = clientes.id and cm.modalidade = :modalidade_fornecedor) as modalidade_fornecedor
- , (select count(1) from clientes_modalidade cm where cm.id_cliente = clientes.id and cm.modalidade = :modalidade_local_cobranca) as modalidade_local_cobranca
- , (select count(1) from clientes_modalidade cm where cm.id_cliente = clientes.id and cm.modalidade = :modalidade_representante) as modalidade_representante
- , (select count(1) from clientes_modalidade cm where cm.id_cliente = clientes.id and cm.modalidade = :modalidade_proprietario) as modalidade_proprietario
- , (select count(1) from clientes_modalidade cm where cm.id_cliente = clientes.id and cm.modalidade = :modalidade_orgao_autuador) as modalidade_orgao_autuador
- , (select count(1) from clientes_modalidade cm where cm.id_cliente = clientes.id and cm.modalidade = :modalidade_armador) as modalidade_armador
- , (select count(1) from clientes_modalidade cm where cm.id_cliente = clientes.id and cm.modalidade = :modalidade_despachante) as modalidade_despachante
- , (select count(1) from clientes_modalidade cm where cm.id_cliente = clientes.id and cm.modalidade = :modalidade_terminal_portuario) as modalidade_terminal_portuario
- , num_dependentes
- , inss_simplificado
- , ind_contrib_icms
- , insc_suframa
- , (select cl.data_hora
- from clientes_logotipo cl
- where cl.id_cliente = clientes.id
- ) as logotipo_data_hora
- , comissao_valor_minimo
- , taf
- , num_registro_estadual
- , rntrc_data_vencimento
- from clientes
- where 1=1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement