brunosiena / MigracaoCrediscoop

0 stars 0 forks source link

CAD #1

Open OhBoyItsWorking opened 12 months ago

OhBoyItsWorking commented 12 months ago
--select '00000CADv104'+ dateformat(getdate(),'YYYYMMDD')
select 'CAD01' + right('000'+cpf,14)
+ right('0000' + cast(CD_POSTO as varchar),4)
+ case tp_funcionario when 'F' then '06' else case fl_pessoa when 'F' then '01' else '04' end end --PULA
+ fl_pessoa
+ left(nm_associado + repeat(' ',80),80)
+ left(nm_associado + repeat(' ',26),26)
+ left(DS_EMAIL  + repeat(' ',150),150)
+ dateformat(isnull(DT_ATUALIZACAO,'1900-01-01'),'YYYYMMDD')
+ 'N' --PULA Restrição serasa
+ 'O'
+ '000000000'
+ '0000'
+ cast(NR_CLASSE_RISCO-1 as varchar)
+ '0'
+ '0'
+ '0'
as out_res from ASSOCIADO;
output to 'C:\Users\Home\Documents\unload\cad01.dat' format text

select 'CAD02' + right('000'+cpf,14)
+ right('0000' + cast(CD_POSTO as varchar),4)
+ fl_estado_civil
+ isnull(FL_REGIME_CASAMENTO,'N')
+ FL_SEXO
+ '00' ---????
+ dateformat(isnull(DT_NASCIMENTO,'1900-01-01'),'YYYYMMDD')
+ left(case isnull(DS_NATURALIDADE,'') when '' then 'NÃO INFORMADO' ELSE isnull(DS_NATURALIDADE,'') END + repeat(' ',20),20)
+ case DS_NACIONALIDADE when 'BRASILEIRA' then 'BR' when 'BRASILEIRO' then 'BR' when 'ALEMA' then 'DE' else 'BR' end
+ right(repeat('0',14)+replace(cast(VL_SALARIO as varchar),'.',''),14)
+ right(repeat('0',15)+REGEXP_SUBSTR(NR_IDENTIDADE, '[0-9]*'),15)
+ left(case isnull(DS_ORGAO_EXPEDIDOR,'') when '' then 'NÃO INFORM' ELSE isnull(DS_ORGAO_EXPEDIDOR,'') END + repeat(' ',10),10)
+ dateformat(isnull(DT_EMISSAO_IDENTIDADE,'1900-01-01'),'YYYYMMDD')
+ left(case isnull(NR_CARTEIRA_PROF,'') when '' then 'NÃO INFORMADO' ELSE isnull(NR_CARTEIRA_PROF,'') END + repeat(' ',15),15)
+ left(case isnull(SG_UF_ORGAO_EXPEDIDOR,'') when '' then '??' ELSE isnull(SG_UF_ORGAO_EXPEDIDOR,'') END + '  ' , 2)
+ left(case isnull(NM_PAI,'') when '' then 'NÃO INFORMADO' ELSE isnull(NM_PAI,'') END + repeat(' ',65),65)
+ left(case isnull(NM_MAE,'') when '' then 'NÃO INFORMADO' ELSE isnull(NM_MAE,'') END + repeat(' ',65),65)
+ '000000'--+ CD_CBO
+ left(case isnull(NM_CONJUGE,'') when '' then 'NÃO INFORMADO' ELSE isnull(NM_CONJUGE,'') END + repeat(' ',65),65)
+ dateformat(isnull(DT_NASCIMENTO_CONJ,'1900-01-01'),'YYYYMMDD')
+ '000000'--+ CD_CARGO_CONJ
+ right(case when nr_cpf_conjuge = '' then '00000000000' else isnull(nr_cpf_conjuge,'00000000000') end,11)
+ right(repeat('0',12)+REGEXP_SUBSTR(NR_IDENTIDADE_CONJ, '[0-9]*'),12)
+ dateformat(isnull(DT_EMISSAO_IDENTID_CONJ,'1900-01-01'),'YYYYMMDD')
+ left(case isnull(DS_ORGAO_EXPEDIDOR_CONJ,'') when '' then 'NÃO INFORMADO' ELSE isnull(DS_ORGAO_EXPEDIDOR_CONJ,'') END + repeat(' ',100),10)
+ repeat(' ',30) --nome da empresa do conjuge
+ left(case isnull(NM_MAE_CONJ,'') when '' then 'NÃO INFORMADO' ELSE isnull(NM_MAE_CONJ,'') END + repeat(' ',65),65)
+ left(case isnull(NM_PAI_CONJ,'') when '' then 'NÃO INFORMADO' ELSE isnull(NM_PAI_CONJ,'') END + repeat(' ',65),65)
+ repeat(' ',60) --email do conjuge
+ right(repeat('0',14)+replace(cast(VL_SALARIO_CONJ as varchar),'.',''),14)
+ right('00'+cast(CD_GRAU_INSTRUCAO as varchar),2) -- o vitor ta trazendo o de-para
+ '000000000' -- numero da matricula vinculada
+ 'O' -- nao tem, ne?
+ right(repeat('0',14)+replace(cast(VL_PENSAO_ALIMENTICIA as varchar),'.',''),14)
+ '000' --qtde meses profissao
+ '??' --naturalidade.... tem o campo DS_NATURALIDADE mas nao da pra confiar
+ left(case isnull(DS_ORGAO_EXPEDIDOR,'') when '' then 'NÃO INFORMADO' ELSE isnull(DS_ORGAO_EXPEDIDOR,'') END + repeat(' ',10),10)
+ '011900' -- nao tem data da renda, tems os campos NR_FAIXA_RENDA e FAIXA_RENDA mas...
+ '5' -- tipo de documento nao tem
+ '0' --campos NR_FAIXA_RENDA ou FAIXA_RENDA mas...
+ '0' -- mod. repres. legal ????
+ '00000000000000' -- valor do patrimonio
as out_res from ASSOCIADO
where fl_pessoa = 'F';
output to 'C:\Users\Home\Documents\unload\cad02.dat' format text

select 'CAD03' + right(repeat('0',14)+REGEXP_SUBSTR(cpf, '[0-9]*'),14)
+ right('0000' + cast(CD_POSTO as varchar),4)
+ 'O'--ramo?
+ '2143'--cooperativa/ tipo de sociedade
+ dateformat(isnull(DT_NASCIMENTO,'1900-01-01'),'YYYYMMDD') -- data da constituição
+ repeat('0',15)--numero da junta. tem na tab empresa..
+ dateformat(isnull(DT_REGISTRO_JC,'1900-01-01'),'YYYYMMDD') -- data do registro, q acho q nao tem
+ repeat('0',15)--numero do arquivo ???? da junta?
+ dateformat(isnull(null ,'1900-01-01'),'YYYYMMDD') -- data do arquivamento?
+ right(repeat('0',9)+isnull(NR_INSCRICAO_ESTADUAL,''),9)
+ repeat('0',9) --inscricao municipal nao tem
+ right(repeat('0',14)+replace(cast(VL_RENDA_PJ_MENSAL as varchar),'.',''),14)
+ isnull(cast(CD_PORTE as varchar),'1') -- ta null
+ '1' -- tipo de controle, me ajuda nisso
+ repeat('0',9) --nao tem cnae
+ '011900' --nao tem data da renda/faturamento
+ '0000' --numero de filiais
+ 'N' --capital aberto
+ '0002' --qualidade da gestao?
+ 'S' --estrutura operacional
+ 'S' --tributação
+ '000000000' -- numero da matricula vinculada
+ 'O' -- nao tem, ne?
+ 'N' -- conta prefeitura, tbm acho q nao tem
+ 'N' -- Ident. MEI
as out_res from ASSOCIADO
where fl_pessoa = 'J';
output to 'C:\Users\Home\Documents\unload\cad03.dat' format text

select 'CAD04' + right('000'+cpf,14)
+ 'O'
+ left(DS_ENDERECO_RES + repeat(' ',60),60)
+ '0000000000' -- Numero endereço
+ left(DS_COMPLEM_RES + repeat(' ',30),30) -- Complemento
+ left(DS_BAIRRO_RES + repeat(' ',30),30) -- bairro
+ left(NR_CEP_RES  + repeat(' ',9),9)
+ '0000000' -- Código Localidade
+ '0000000000'
+ 'N'
es from ASSOCIADO;
output to 'C:\Users\Home\Documents\unload\cad01.dat' format text

select 'CAD05' + right('000'+cpf,14)
+ '1'
+ right(repeat('0',3)+replace(cast(NR_DDD_TEL_RES as varchar),'.',''),3)
+ right(repeat('0',3)+replace(cast(NR_TEL_RES as varchar),'.',''),3) 
+ repeat(' ',40)
+ 'N' -- notificacao de cheque especial
as out_res from ASSOCIADO
union all
select 'CAD05' + right('000'+cpf,14)
+ '2'
+ right(repeat('0',3)+replace(cast(NR_DDD_TEL_PRO as varchar),'.',''),3)
+ right(repeat('0',3)+replace(cast(NR_TEL_PRO as varchar),'.',''),3) 
+ repeat(' ',40)
+ 'N' -- notificacao de cheque especial
as out_res from ASSOCIADO;
output to 'C:\Users\Home\Documents\unload\cad05.dat' format text
OhBoyItsWorking commented 11 months ago

pessoa fisica, CAD02:

  1. estado civil = I (73 rows)
  2. regime de casamento = null (1046)
  3. sexo = "" (6)
  4. dependentes ?
  5. emissor ident. + data vazio ?
  6. registro profissional + orgao + uf
  7. cargo.cd_cbo = null (420)
  8. CD_GRAU_INSTRUCAO?
OhBoyItsWorking commented 11 months ago

select t.table_name, c. from systabcol c key join systab t on t.table_id=c.table_id where /t.table_name='associado' and */c.column_name like '%contrato%'

OhBoyItsWorking commented 11 months ago

select 'CAD02' + right('000'+cpf,14)