Advertisement
Guest User

Untitled

a guest
Jun 15th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 6.26 KB | None | 0 0
  1. select (Select est.NOME from estados est where est.SIGLA = clientes.ESTADO       ) as nomeestado
  2.      , (Select est.NOME from estados est where est.SIGLA = clientes.COB_ESTADO   ) as cob_nomeestado
  3.      , clientes.cnpj_cpf
  4.      , CODIGO, NOME, FANTASIA, ENDERECO, BAIRRO, DOC_PESSOA_ESTRANGEIRA, TIPO_PESSOA
  5.      , CIDADE, ESTADO, PAIS, CEP, FONE
  6.      , FAX, CELULAR, EMAIL, CONTATO, TIPO
  7.      , CGC, INSC, CPF, RG, DATA_CAD
  8.      , ULT_COMPRA, OBS, REPRESENT
  9.      , COMISSAO
  10.      , (select ca.valor
  11.           from clientes_atributo ca
  12.          where ca.id_cliente = clientes.id
  13.            and ca.cod_atributo = :atri_ctrc_icms_aliquota
  14.        ) as aliquota
  15.      , PRACA_PGTO, INSC_MUN, EMPRESA
  16.      , REF, CIDADES_GERAL_ID, COD_IBGE, NUMERO, PAISES_ID
  17.      , (select first 1 cle.endereco from clientes_endereco cle where cle.id_cliente = clientes.id and cle.tipo = 'COBRANCA') as cob_endereco
  18.      , (select first 1 cle.numero from clientes_endereco cle where cle.id_cliente = clientes.id and cle.tipo = 'COBRANCA') as cob_numero
  19.      , (select first 1 cle.complemento from clientes_endereco cle where cle.id_cliente = clientes.id and cle.tipo = 'COBRANCA') as cob_complemento
  20.      , (select first 1 cle.bairro from clientes_endereco cle where cle.id_cliente = clientes.id and cle.tipo = 'COBRANCA') as cob_bairro
  21.      , (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
  22.      , (select first 1 cle.uf from clientes_endereco cle where cle.id_cliente = clientes.id and cle.tipo = 'COBRANCA') as cob_estado
  23.      , (select first 1 cle.cep from clientes_endereco cle where cle.id_cliente = clientes.id and cle.tipo = 'COBRANCA') as cob_cep
  24.      , (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
  25.      , (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
  26.      , DATA_NASC, DADOS_BANCARIOS
  27.      , COMISSAO_CTRCCIF
  28.      , EMAIL2, ID, CODIGO_LOCAL_COBRANCA, ENQUADRAMENTO_CFOP
  29.      , COMPLEMENTO, ID_CIDADES_SETOR, ID_CENTRO_CUSTO, ID_CENTRO_RECEITA
  30.      , (select s.descricao from cidades_setor s where s.id = clientes.id_cidades_setor) as descricao_setor
  31.      , pis_nit, rntrc, inss, rg_uf, rg_orgao_expedidor
  32.  
  33.      , (select m.id     from motoristas m where m.id_cliente = clientes.id) as id_motorista
  34.      , (select m.codigo from motoristas m where m.id_cliente = clientes.id) as codigo_motorista
  35.      , (select first 1 f.codigo from funcionarios f where f.id_cliente = clientes.id order by coalesce(f.data_demissao, '') asc) as codigo_funcionario
  36.      , (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
  37.  
  38.      , (select p.nome from paises p where p.id = clientes.paises_id) pais_nome
  39.      , (select 'Cadastro vinculado a empresa'
  40.          from empresa emp
  41.         where emp.codigo = empresa
  42.           and coalesce(cgc, '''') = (select saida
  43.                                        from somentenumeros(emp.cnpj))) as vinculo_clientes_empresa
  44.      , ID_CONDICAO_PAGAMENTO
  45.      , (select p.descricao from condicoes_pagamento p where p.id = clientes.id_condicao_pagamento) as DESCRICAO_CONDICAO_PAGAMENTO
  46.      , (select p.codigo from condicoes_pagamento p where p.id = clientes.id_condicao_pagamento) as CODIGO_CONDICAO_PAGAMENTO
  47.      , (select p.parcelas from condicoes_pagamento p where p.id = clientes.id_condicao_pagamento) as NUM_PARCELAS
  48.      , (select p.intervalo_dias from condicoes_pagamento p where p.id = clientes.id_condicao_pagamento) as INTERVALO_DIAS
  49.      , (select p.dias_vencimento from condicoes_pagamento p where p.id = clientes.id_condicao_pagamento) as VENCIMENTO_1_PARCELA
  50.  
  51.      , (select fc.codigo from fcen_custo fc where fc.id = clientes.id_centro_custo) as centcusto
  52.      , (select fc.codigo from fcen_custo fc where fc.id = clientes.id_centro_receita) as centreceita
  53.      , id_cliente_pai
  54.      , rg_data_emissao
  55.      , codigo_cidade_naturalidade
  56.      , (select cg.nome || '-' || cg.uf from cidades_geral cg where cg.codigo = clientes.codigo_cidade_naturalidade) as naturalidade
  57.      , sexo
  58.      , (select cg.cod_ibge || cg.dv
  59.           from cidades_geral cg
  60.          where clientes.cidades_geral_id = cg.codigo) as cod_ibge_completo
  61.      , (select count(1) from clientes_modalidade cm where cm.id_cliente = clientes.id and cm.modalidade = :modalidade_cliente) as modalidade_cliente
  62.      , (select count(1) from clientes_modalidade cm where cm.id_cliente = clientes.id and cm.modalidade = :modalidade_fornecedor) as modalidade_fornecedor
  63.      , (select count(1) from clientes_modalidade cm where cm.id_cliente = clientes.id and cm.modalidade = :modalidade_local_cobranca) as modalidade_local_cobranca
  64.      , (select count(1) from clientes_modalidade cm where cm.id_cliente = clientes.id and cm.modalidade = :modalidade_representante) as modalidade_representante
  65.      , (select count(1) from clientes_modalidade cm where cm.id_cliente = clientes.id and cm.modalidade = :modalidade_proprietario) as modalidade_proprietario
  66.      , (select count(1) from clientes_modalidade cm where cm.id_cliente = clientes.id and cm.modalidade = :modalidade_orgao_autuador) as modalidade_orgao_autuador
  67.      , (select count(1) from clientes_modalidade cm where cm.id_cliente = clientes.id and cm.modalidade = :modalidade_armador) as modalidade_armador
  68.      , (select count(1) from clientes_modalidade cm where cm.id_cliente = clientes.id and cm.modalidade = :modalidade_despachante) as modalidade_despachante
  69.      , (select count(1) from clientes_modalidade cm where cm.id_cliente = clientes.id and cm.modalidade = :modalidade_terminal_portuario) as modalidade_terminal_portuario
  70.      , num_dependentes
  71.      , inss_simplificado
  72.      , ind_contrib_icms
  73.      , insc_suframa
  74.      , (select cl.data_hora
  75.           from clientes_logotipo cl
  76.          where cl.id_cliente = clientes.id
  77.        ) as logotipo_data_hora
  78.      , comissao_valor_minimo
  79.      , taf
  80.      , num_registro_estadual
  81.      , rntrc_data_vencimento
  82.   from clientes
  83.  where 1=1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement