Fórum Update com If ou Case? #361937
01/08/2008
0
Tem como fazer um Update com If ou Case?
update tabela set
case
when campo = 1 then campo = 20
where codigo = 1
ou
update tabela set
if condicao > 0
campo = 1
where codigo > 20
update tabela set
case
when campo = 1 then campo = 20
where codigo = 1
ou
update tabela set
if condicao > 0
campo = 1
where codigo > 20
Guigosnet
Curtir tópico
+ 0
Responder
Posts
01/08/2008
Fabianosales
Tem sim.
A sintaxe ANSI (testei somente no firebird, mas deve funcionar para a maioria dos bancos relacionais) é:
A sintaxe ANSI (testei somente no firebird, mas deve funcionar para a maioria dos bancos relacionais) é:
UPDATE TBL SET CODIGO = CASE CONDICAO WHEN 0 THEN NULL WHEN 1 THEN 1000 WHEN 2 THEN 2000 WHEN 3 THEN 3000 WHEN 4 THEN 4000 WHEN 5 THEN 5000 END
Responder
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)