Last active
March 15, 2017 13:18
-
-
Save primogf/bc0239d7e4657b8b8332a740239a9b46 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
select * from AccountingBalanceSheet; | |
desc AccountingBalanceSheet; | |
select * from AccountingBalanceSheetAccountBalance;DELIMITER $$ | |
CREATE DEFINER=`root`@`localhost` PROCEDURE `proc_teste`() | |
BEGIN | |
-- declarando variaveis | |
DECLARE fim INT DEFAULT false; | |
DECLARE var_id_dado_coletado INT; | |
DECLARE var_valor_identificador varchar(45); | |
DECLARE var_pergunta varchar(100); | |
DECLARE var_resposta varchar(100); | |
DECLARE var_des_resposta varchar(100); | |
DECLARE tmp_valor_identificador varchar(45); | |
DECLARE tmp_nome varchar(100); | |
DECLARE tmp_cpf varchar(100); | |
DECLARE tmp_nome_beneficiado varchar(100); | |
DECLARE tmp_cpf_beneficiado varchar(100); | |
DECLARE tmp_estado varchar(100); | |
DECLARE tmp_municipio varchar(100); | |
DECLARE tmp_bairro varchar(100); | |
DECLARE tmp_logradouro varchar(100); | |
DECLARE tmp_endereco varchar(100); | |
DECLARE tmp_numero varchar(100); | |
DECLARE tmp_complemento varchar(100); | |
DECLARE tmp_cep varchar(100); | |
DECLARE tmp_idade boolean; | |
DECLARE tmp_carcaca boolean; | |
DECLARE tmp_borracha boolean; | |
-- criando o cursor | |
DECLARE curDados CURSOR FOR | |
SELECT | |
dc.id_dado_coletado, | |
dc.valor_identificador AS uc, | |
pep.des AS pergunta, | |
p.resposta_livre, | |
pepi.des AS resposta | |
FROM | |
erp_dado_coletado dc | |
INNER JOIN | |
erp_dado_coletado_item dci ON (dci.id_dado_coletado = dc.id_dado_coletado | |
AND dci.stat <> 0) | |
INNER JOIN | |
erp_pesquisa p ON (p.id_pesquisa = dci.id_registro | |
AND tabela_registro = 'erp_pesquisa' | |
AND p.stat <> 0) | |
INNER JOIN | |
com_projeto_elemento_pesquisa pep ON (pep.id_projeto_elemento_pesquisa = p.id_projeto_elemento_pesquisa) | |
LEFT JOIN | |
com_projeto_elemento_pesquisa_item pepi ON (pepi.id_projeto_elemento_pesquisa_item = p.id_projeto_elemento_pesquisa_item) | |
LEFT JOIN | |
com_projeto_elemento pe ON (pe.id_projeto_elemento = dc.id_projeto_elemento) | |
where dc.valor_identificador in ( | |
select | |
d.valor_identificador | |
from | |
erp_dado_coletado d | |
inner join erp_dado_coletado_item i on d.id_dado_coletado = i.id_dado_coletado and i.stat <> 0 and i.tabela_registro = 'erp_pesquisa' | |
inner join com_projeto_elemento e on e.id_projeto_elemento = d.id_projeto_elemento and e.stat <> 0 | |
inner join erp_pesquisa p on p.id_pesquisa = i.id_registro and p.stat <> 0 | |
where | |
d.dt_inicial >= '2016-08-08 00:00:00' and d.dt_inicial <= '2016-11-30 23:59:59' -- and d.status_qualidade_pesquisa = 1 | |
and e.id_projeto = 187 and e.id_projeto_elemento = 8 | |
-- and (p.id_projeto_elemento_pesquisa_item = 230 and p.id_projeto_elemento_pesquisa_item = 237 and p.id_projeto_elemento_pesquisa_item = 238) | |
) and dc.stat <> 0 order by dc.valor_identificador; | |
DECLARE CONTINUE handler FOR NOT found SET fim = TRUE; | |
-- criando tabela temporaria | |
DROP TEMPORARY TABLE IF EXISTS tmp_teste; | |
CREATE TEMPORARY TABLE tmp_teste ( | |
valor_identificador varchar(45), | |
nome_titular varchar(100), | |
cpf_titular varchar(100), | |
nome_beneficiado varchar(100), | |
cpf_beneficiado varchar(100), | |
estado varchar(100), | |
municipio varchar(100), | |
bairro varchar(100), | |
logradouro varchar(100), | |
endereco varchar(100), | |
numero varchar(100), | |
complemento varchar(100), | |
cep varchar(100) | |
)ENGINE=MyISAM DEFAULT CHARSET=latin1; | |
-- zerando variaveis | |
SET tmp_valor_identificador = ''; | |
SET tmp_idade = false; | |
SET tmp_carcaca = false; | |
SET tmp_borracha = false; | |
OPEN curDados; | |
-- loop no cursor e gravando na tabela temporaria | |
READ_LOOP:LOOP | |
FETCH curDados | |
INTO | |
var_id_dado_coletado, | |
var_valor_identificador, | |
var_pergunta, | |
var_resposta, | |
var_des_resposta; | |
IF (tmp_valor_identificador = '') then | |
set tmp_valor_identificador = var_valor_identificador; | |
end IF; | |
-- qual é pergunta se for endereco se for alguma dessas eu guardo em variaveis | |
if(tmp_valor_identificador = var_valor_identificador) then | |
if((var_pergunta = 'QUAL A IDADE DA GELADEIRA?') && (var_des_resposta = 'MAIOR QUE 5 ANOS'))then | |
set tmp_idade = true; | |
end if; | |
if((var_pergunta = 'COMO ESTA A CARCACA DA GELADEIRA ?') && (var_des_resposta = 'RUIM'))then | |
set tmp_carcaca = true; | |
end if; | |
if((var_pergunta = 'COMO ESTA A BORRACHA DA GELADEIRA?') && (var_des_resposta = 'RUIM'))then | |
set tmp_borracha = true; | |
end if; | |
if(var_pergunta = 'NOME TITULAR')then | |
set tmp_nome = var_resposta; | |
end if; | |
if(var_pergunta = 'CPF TITULAR')then | |
set tmp_cpf = var_resposta; | |
end if; | |
if(var_pergunta = 'NOME BENEFICIADO')then | |
set tmp_nome_beneficiado = var_resposta; | |
end if; | |
if(var_pergunta = 'CPF BENEFICIADO')then | |
set tmp_cpf_beneficiado = var_resposta; | |
end if; | |
if(var_pergunta = 'ESTADO')then | |
set tmp_estado = var_des_resposta; | |
end if; | |
if(var_pergunta = 'MUNICIPIO')then | |
set tmp_municipio = var_des_resposta; | |
end if; | |
if(var_pergunta = 'BAIRRO')then | |
set tmp_bairro = var_des_resposta; | |
end if; | |
if(var_pergunta = 'LOGRADOURO')then | |
set tmp_logradouro = var_des_resposta; | |
end if; | |
if(var_pergunta = 'ENDERECO')then | |
set tmp_endereco = var_resposta; | |
end if; | |
if(var_pergunta = 'NUMERO')then | |
set tmp_numero = var_resposta; | |
end if; | |
if(var_pergunta = 'COMPLEMENTO')then | |
set tmp_complemento = var_resposta; | |
end if; | |
if(var_pergunta = 'CEP')then | |
set tmp_cep = var_resposta; | |
end if; | |
set tmp_valor_identificador = var_valor_identificador; | |
ELSE | |
-- if(tmp_idade = true and tmp_carcaca = true and tmp_borracha = true) then | |
DELIMITER $$ | |
CREATE DEFINER=`root`@`localhost` PROCEDURE `proc_teste`() | |
BEGIN | |
-- declarando variaveis | |
DECLARE fim INT DEFAULT false; | |
DECLARE var_id_dado_coletado INT; | |
DECLARE var_valor_identificador varchar(45); | |
DECLARE var_pergunta varchar(100); | |
DECLARE var_resposta varchar(100); | |
DECLARE var_des_resposta varchar(100); | |
DECLARE tmp_valor_identificador varchar(45); | |
DECLARE tmp_nome varchar(100); | |
DECLARE tmp_cpf varchar(100); | |
DECLARE tmp_nome_beneficiado varchar(100); | |
DECLARE tmp_cpf_beneficiado varchar(100); | |
DECLARE tmp_estado varchar(100); | |
DECLARE tmp_municipio varchar(100); | |
DECLARE tmp_bairro varchar(100); | |
DECLARE tmp_logradouro varchar(100); | |
DECLARE tmp_endereco varchar(100); | |
DECLARE tmp_numero varchar(100); | |
DECLARE tmp_complemento varchar(100); | |
DECLARE tmp_cep varchar(100); | |
DECLARE tmp_idade boolean; | |
DECLARE tmp_carcaca boolean; | |
DECLARE tmp_borracha boolean; | |
-- criando o cursor | |
DECLARE curDados CURSOR FOR | |
SELECT | |
dc.id_dado_coletado, | |
dc.valor_identificador AS uc, | |
pep.des AS pergunta, | |
p.resposta_livre, | |
pepi.des AS resposta | |
FROM | |
erp_dado_coletado dc | |
INNER JOIN | |
erp_dado_coletado_item dci ON (dci.id_dado_coletado = dc.id_dado_coletado | |
AND dci.stat <> 0) | |
INNER JOIN | |
erp_pesquisa p ON (p.id_pesquisa = dci.id_registro | |
AND tabela_registro = 'erp_pesquisa' | |
AND p.stat <> 0) | |
INNER JOIN | |
com_projeto_elemento_pesquisa pep ON (pep.id_projeto_elemento_pesquisa = p.id_projeto_elemento_pesquisa) | |
LEFT JOIN | |
com_projeto_elemento_pesquisa_item pepi ON (pepi.id_projeto_elemento_pesquisa_item = p.id_projeto_elemento_pesquisa_item) | |
LEFT JOIN | |
com_projeto_elemento pe ON (pe.id_projeto_elemento = dc.id_projeto_elemento) | |
where dc.valor_identificador in ( | |
select | |
d.valor_identificador | |
from | |
erp_dado_coletado d | |
inner join erp_dado_coletado_item i on d.id_dado_coletado = i.id_dado_coletado and i.stat <> 0 and i.tabela_registro = 'erp_pesquisa' | |
inner join com_projeto_elemento e on e.id_projeto_elemento = d.id_projeto_elemento and e.stat <> 0 | |
inner join erp_pesquisa p on p.id_pesquisa = i.id_registro and p.stat <> 0 | |
where | |
d.dt_inicial >= '2016-08-08 00:00:00' and d.dt_inicial <= '2016-11-30 23:59:59' -- and d.status_qualidade_pesquisa = 1 | |
and e.id_projeto = 187 and e.id_projeto_elemento = 8 | |
-- and (p.id_projeto_elemento_pesquisa_item = 230 and p.id_projeto_elemento_pesquisa_item = 237 and p.id_projeto_elemento_pesquisa_item = 238) | |
) and dc.stat <> 0 order by dc.valor_identificador; | |
DECLARE CONTINUE handler FOR NOT found SET fim = TRUE; | |
-- criando tabela temporaria | |
DROP TEMPORARY TABLE IF EXISTS tmp_teste; | |
CREATE TEMPORARY TABLE tmp_teste ( | |
valor_identificador varchar(45), | |
nome_titular varchar(100), | |
cpf_titular varchar(100), | |
nome_beneficiado varchar(100), | |
cpf_beneficiado varchar(100), | |
estado varchar(100), | |
municipio varchar(100), | |
bairro varchar(100), | |
logradouro varchar(100), | |
endereco varchar(100), | |
numero varchar(100), | |
complemento varchar(100), | |
cep varchar(100) | |
)ENGINE=MyISAM DEFAULT CHARSET=latin1; | |
-- zerando variaveis | |
SET tmp_valor_identificador = ''; | |
SET tmp_idade = false; | |
SET tmp_carcaca = false; | |
SET tmp_borracha = false; | |
OPEN curDados; | |
-- loop no cursor e gravando na tabela temporaria | |
READ_LOOP:LOOP | |
FETCH curDados | |
INTO | |
var_id_dado_coletado, | |
var_valor_identificador, | |
var_pergunta, | |
var_resposta, | |
var_des_resposta; | |
IF (tmp_valor_identificador = '') then | |
set tmp_valor_identificador = var_valor_identificador; | |
end IF; | |
-- qual é pergunta se for endereco se for alguma dessas eu guardo em variaveis | |
if(tmp_valor_identificador = var_valor_identificador) then | |
if((var_pergunta = 'QUAL A IDADE DA GELADEIRA?') && (var_des_resposta = 'MAIOR QUE 5 ANOS'))then | |
set tmp_idade = true; | |
end if; | |
if((var_pergunta = 'COMO ESTA A CARCACA DA GELADEIRA ?') && (var_des_resposta = 'RUIM'))then | |
set tmp_carcaca = true; | |
end if; | |
if((var_pergunta = 'COMO ESTA A BORRACHA DA GELADEIRA?') && (var_des_resposta = 'RUIM'))then | |
set tmp_borracha = true; | |
end if; | |
if(var_pergunta = 'NOME TITULAR')then | |
set tmp_nome = var_resposta; | |
end if; | |
if(var_pergunta = 'CPF TITULAR')then | |
set tmp_cpf = var_resposta; | |
end if; | |
if(var_pergunta = 'NOME BENEFICIADO')then | |
set tmp_nome_beneficiado = var_resposta; | |
end if; | |
if(var_pergunta = 'CPF BENEFICIADO')then | |
set tmp_cpf_beneficiado = var_resposta; | |
end if; | |
if(var_pergunta = 'ESTADO')then | |
set tmp_estado = var_des_resposta; | |
end if; | |
if(var_pergunta = 'MUNICIPIO')then | |
set tmp_municipio = var_des_resposta; | |
end if; | |
if(var_pergunta = 'BAIRRO')then | |
set tmp_bairro = var_des_resposta; | |
end if; | |
if(var_pergunta = 'LOGRADOURO')then | |
set tmp_logradouro = var_des_resposta; | |
end if; | |
if(var_pergunta = 'ENDERECO')then | |
set tmp_endereco = var_resposta; | |
end if; | |
if(var_pergunta = 'NUMERO')then | |
set tmp_numero = var_resposta; | |
end if; | |
if(var_pergunta = 'COMPLEMENTO')then | |
set tmp_complemento = var_resposta; | |
end if; | |
if(var_pergunta = 'CEP')then | |
set tmp_cep = var_resposta; | |
end if; | |
set tmp_valor_identificador = var_valor_identificador; | |
ELSE | |
-- if(tmp_idade = true and tmp_carcaca = true and tmp_borracha = true) then | |
insert into tmp_teste (valor_identificador,nome_titular,cpf_titular,nome_beneficiado,cpf_beneficiado,estado,municipio,bairro,logradouro,endereco,numero,complemento,cep) values (tmp_valor_identificador,tmp_nome,tmp_cpf,tmp_nome_beneficiado,tmp_cpf_beneficiado,tmp_estado,tmp_municipio,tmp_bairro,tmp_logradouro,tmp_endereco,tmp_numero,tmp_complemento,tmp_cep); | |
-- end if; | |
set tmp_nome = ''; | |
set tmp_cpf = ''; | |
set tmp_nome_beneficiado = ''; | |
set tmp_cpf_beneficiado = ''; | |
set tmp_estado = ''; | |
set tmp_municipio = ''; | |
set tmp_bairro = ''; | |
set tmp_logradouro = ''; | |
set tmp_endereco = ''; | |
set tmp_numero = ''; | |
set tmp_complemento = ''; | |
set tmp_cep = ''; | |
set tmp_idade = false; | |
set tmp_carcaca = false; | |
set tmp_borracha = false; | |
if((var_pergunta = 'QUAL A IDADE DA GELADEIRA?') && (var_des_resposta = 'MAIOR QUE 5 ANOS'))then | |
set tmp_idade = true; | |
end if; | |
if((var_pergunta = 'COMO ESTA A CARCACA DA GELADEIRA ?') && (var_des_resposta = 'RUIM'))then | |
set tmp_carcaca = true; | |
end if; | |
if((var_pergunta = 'COMO ESTA A BORRACHA DA GELADEIRA?') && (var_des_resposta = 'RUIM'))then | |
set tmp_borracha = true; | |
end if; | |
if(var_pergunta = 'NOME TITULAR')then | |
set tmp_nome = var_des_resposta; | |
end if; | |
if(var_pergunta = 'CPF TITULAR')then | |
set tmp_cpf = var_des_resposta; | |
end if; | |
if(var_pergunta = 'NOME BENEFICIADO')then | |
set tmp_nome_beneficiado = var_resposta; | |
end if; | |
if(var_pergunta = 'CPF BENEFICIADO')then | |
set tmp_cpf_beneficiado = var_resposta; | |
end if; | |
if(var_pergunta = 'ESTADO')then | |
set tmp_estado = var_resposta; | |
end if; | |
if(var_pergunta = 'MUNICIPIO')then | |
set tmp_municipio = var_resposta; | |
end if; | |
if(var_pergunta = 'BAIRRO')then | |
set tmp_bairro = var_resposta; | |
end if; | |
if(var_pergunta = 'LOGRADOURO')then | |
set tmp_logradouro = var_resposta; | |
end if; | |
if(var_pergunta = 'ENDERECO')then | |
set tmp_endereco = var_des_resposta; | |
end if; | |
if(var_pergunta = 'NUMERO')then | |
set tmp_numero = var_resposta; | |
end if; | |
if(var_pergunta = 'COMPLEMENTO')then | |
set tmp_complemento = var_resposta; | |
end if; | |
if(var_pergunta = 'CEP')then | |
set tmp_cep = var_resposta; | |
end if; | |
set tmp_valor_identificador = var_valor_identificador; | |
end if; | |
IF fim THEN | |
LEAVE read_loop; | |
end IF; | |
end LOOP; | |
close curDados; | |
-- select na tabela temporaria | |
SELECT * FROM tmp_teste order by 1; | |
-- deletando tabela temporaria | |
DROP TEMPORARY TABLE IF EXISTS tmp_teste; | |
END$$ | |
DELIMITER ; | |
tificador,nome_titular,cpf_titular,nome_beneficiado,cpf_beneficiado,estado,municipio,bairro,logradouro,endereco,numero,complemento,cep) values (tmp_valor_identificador,tmp_nome,tmp_cpf,tmp_nome_beneficiado,tmp_cpf_beneficiado,tmp_estado,tmp_municipio,tmp_bairro,tmp_logradouro,tmp_endereco,tmp_numero,tmp_complemento,tmp_cep); | |
-- end if; | |
set tmp_nome = ''; | |
set tmp_cpf = ''; | |
set tmp_nome_beneficiado = ''; | |
set tmp_cpf_beneficiado = ''; | |
set tmp_estado = ''; | |
set tmp_municipio = ''; | |
set tmp_bairro = ''; | |
set tmp_logradouro = ''; | |
set tmp_endereco = ''; | |
set tmp_numero = ''; | |
set tmp_complemento = ''; | |
set tmp_cep = ''; | |
set tmp_idade = false; | |
set tmp_carcaca = false; | |
set tmp_borracha = false; | |
if((var_pergunta = 'QUAL A IDADE DA GELADEIRA?') && (var_des_resposta = 'MAIOR QUE 5 ANOS'))then | |
set tmp_idade = true; | |
end if; | |
if((var_pergunta = 'COMO ESTA A CARCACA DA GELADEIRA ?') && (var_des_resposta = 'RUIM'))then | |
set tmp_carcaca = true; | |
end if; | |
if((var_pergunta = 'COMO ESTA A BORRACHA DA GELADEIRA?') && (var_des_resposta = 'RUIM'))then | |
set tmp_borracha = true; | |
end if; | |
if(var_pergunta = 'NOME TITULAR')then | |
set tmp_nome = var_des_resposta; | |
end if; | |
if(var_pergunta = 'CPF TITULAR')then | |
set tmp_cpf = var_des_resposta; | |
end if; | |
if(var_pergunta = 'NOME BENEFICIADO')then | |
set tmp_nome_beneficiado = var_resposta; | |
end if; | |
if(var_pergunta = 'CPF BENEFICIADO')then | |
set tmp_cpf_beneficiado = var_resposta; | |
end if; | |
if(var_pergunta = 'ESTADO')then | |
set tmp_estado = var_resposta; | |
end if; | |
if(var_pergunta = 'MUNICIPIO')then | |
set tmp_municipio = var_resposta; | |
end if; | |
if(var_pergunta = 'BAIRRO')then | |
set tmp_bairro = var_resposta; | |
end if; | |
if(var_pergunta = 'LOGRADOURO')then | |
set tmp_logradouro = var_resposta; | |
end if; | |
if(var_pergunta = 'ENDERECO')then | |
set tmp_endereco = var_des_resposta; | |
end if; | |
if(var_pergunta = 'NUMERO')then | |
set tmp_numero = var_resposta; | |
end if; | |
if(var_pergunta = 'COMPLEMENTO')then | |
set tmp_complemento = var_resposta; | |
end if; | |
if(var_pergunta = 'CEP')then | |
set tmp_cep = var_resposta; | |
end if; | |
set tmp_valor_identificador = var_valor_identificador; | |
end if; | |
IF fim THEN | |
LEAVE read_loop; | |
end IF; | |
end LOOP; | |
close curDados; | |
-- select na tabela temporaria | |
SELECT * FROM tmp_teste order by 1; | |
-- deletando tabela temporaria | |
DROP TEMPORARY TABLE IF EXISTS tmp_teste; | |
END$$ | |
DELIMITER ; | |
select * from AccountingBalanceSheetLayout; | |
select * from AccountingBalanceSheetLayoutAccount; | |
select * from con_balanco_saldo; | |
-- delete from AccountingBalanceSheet; | |
-- delete from AccountingBalanceSheetAccountBalance; | |
-- delete from AccountingBalanceSheetLayout; | |
-- delete from AccountingBalanceSheetLayoutAccount; | |
select | |
e.* | |
from | |
erp_parceiro p | |
inner join erp_parceiro_endereco e on e.id_parceiro = p.id_parceiro and e.stat <> 0 | |
where | |
e.id_parceiro in (114141); | |
select | |
count(*) | |
from | |
erp_parceiro_endereco | |
where | |
id_concessionaria = 12 and flag_tipo_endereco is null and stat <> 0; | |
update erp_parceiro_endereco set flag_tipo_endereco = 3 where id_concessionaria = 12 and flag_tipo_endereco is null and stat <> 0; | |
-- delete from AccountingBalanceSheet where id_balanco = 59 | |
-- delete from AccountingBalanceSheetAccountBalance where id_balanco = 59 | |
desc BalanceSheetLayout; | |
desc TableOfAccountsBalanceSheetLayout; | |
select | |
sum(a.saldo_conta) | |
from | |
TableOfAccountsBalance b | |
inner join AccountsBalance a on a.id_balanco = b.id_balanco and a.stat <> 0 | |
where | |
b.id_empresa = 29 | |
and b.tipo_balanco = 1 | |
and b.dt_saldo between '2015-12-31 00:00:00' and '2015-12-31 23:59:59'; | |
select * from AccountsBalance where id_balanco = 42; | |
select * from TableOfAccounts; | |
select * from con_planodecontas_interno; | |
desc TableOfAccounts; | |
select | |
concat('insert into TableOfAccounts (id_tipo,idCurrency,cod,des,niv_1,niv_2,niv_3,niv_4,niv_5,bloqueado,stat) value (1,1,',cod,',','''',des,'''',',',niv_1,',',niv_2,',',niv_3,',',niv_4,',',niv_5,',0,1);') as comando | |
from | |
con_planodecontas_interno | |
where | |
stat <> 0; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment