rebsonm Novato

Registrado: Segunda-Feira, 25 de Março de 2013 Mensagens: 1
|
Enviada: Seg Mar 25, 2013 3:57 pm Assunto: Dúvida com IF usando um resultado de um Select count |
|
|
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? |
|