ActiveDelphi - Índice do Fórum ActiveDelphi
.: O site do programador Delphi! :.
 
 FAQFAQ   PesquisarPesquisar   MembrosMembros   GruposGrupos   RegistrarRegistrar 
 PerfilPerfil   Entrar e ver Mensagens ParticularesEntrar e ver Mensagens Particulares   EntrarEntrar 

Dúvida com IF usando um resultado de um Select count

 
Novo Tópico   Responder Mensagem    ActiveDelphi - Índice do Fórum -> Banco de Dados
Exibir mensagem anterior :: Exibir próxima mensagem  
Autor Mensagem
rebsonm
Novato
Novato


Registrado: Segunda-Feira, 25 de Março de 2013
Mensagens: 1

MensagemEnviada: Seg Mar 25, 2013 3:57 pm    Assunto: Dúvida com IF usando um resultado de um Select count Responder com Citação

Olá, boa tarde a todos. Não domino bem o SQL, mas estou precisando criar um código que atualize algumas informações no meu banco. Criei o seguinte código...


select ctr, count(ctr) as Qtd
from tab00101 where tipoparcela = 'L'
group by ctr
having
COUNT(ctr) = 6

Com esse resultado, ele retornou as informações que eu gostaria, porém, preciso que ele atualize as informações que tem nessa mesma tabela

update tab00101 set sequencia = '1' where numeroparcela = '1' and tipoparcela = 'L'
update tab00101 set sequencia = '2' where numeroparcela = '2' and tipoparcela = 'L'
update tab00101 set sequencia = '3' where numeroparcela = '3' and tipoparcela = 'L'
update tab00101 set sequencia = '4' where numeroparcela = '4' and tipoparcela = 'L'
update tab00101 set sequencia = '5' where numeroparcela = '5' and tipoparcela = 'L'
update tab00101 set sequencia = '6' where numeroparcela = '6' and tipoparcela = 'L'
update tab00101 set sequencia = '7' where numeroparcela = '1' and tipoparcela = 'S'
update tab00101 set sequencia = '8' where numeroparcela = '2' and tipoparcela = 'S'

Preciso que também aconteça o seguinte

select ctr, count(ctr) as Qtd
from tab00101 where tipoparcela = 'L'
group by ctr
having
COUNT(ctr) = 5

update tab00101 set sequencia = '1' where numeroparcela = '1' and tipoparcela = 'L'
update tab00101 set sequencia = '2' where numeroparcela = '2' and tipoparcela = 'L'
update tab00101 set sequencia = '3' where numeroparcela = '3' and tipoparcela = 'L'
update tab00101 set sequencia = '4' where numeroparcela = '4' and tipoparcela = 'L'
update tab00101 set sequencia = '5' where numeroparcela = '5' and tipoparcela = 'L'
update tab00101 set sequencia = '6' where numeroparcela = '1' and tipoparcela = 'S'
update tab00101 set sequencia = '7' where numeroparcela = '2' and tipoparcela = 'S'
update tab00101 set sequencia = '8' where numeroparcela = '3' and tipoparcela = 'S'

e assim por diante... com 4... 3... 2...1... Não consigo montar um IF... Alguém poderia me ajudar?
Voltar ao Topo
Ver o perfil de Usuários Enviar Mensagem Particular
Mostrar os tópicos anteriores:   
Novo Tópico   Responder Mensagem    ActiveDelphi - Índice do Fórum -> Banco de Dados Todos os horários são GMT - 3 Horas
Página 1 de 1

 
Ir para:  
Enviar Mensagens Novas: Proibido.
Responder Tópicos Proibido
Editar Mensagens: Proibido.
Excluir Mensagens: Proibido.
Votar em Enquetes: Proibido.


Powered by phpBB © 2001, 2005 phpBB Group
Traduzido por: Suporte phpBB