Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Bases de datos > Firebird e Interbase
Registrarse FAQ Miembros Calendario Guía de estilo Buscar Temas de Hoy Marcar Foros Como Leídos

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 12-12-2017
Avatar de Angel.Matilla
Angel.Matilla Angel.Matilla is offline
Miembro
 
Registrado: ene 2007
Posts: 1.350
Poder: 19
Angel.Matilla Va por buen camino
¿Error en COALESCE?

Estoy probando este query con SQL Manager:
Código:
SELECT Apellidos, Referencia, Nif, Codigo, COALESCE(Referencia, Nif, CAST(Codigo AS VARCHAR(10)))
FROM Persona
ORDER BY 2,3,4,5
Según lo que llevo leido, la cláusula COALESCE me devolvería un valor NULL si los tres argumentos lo son. Sin embargo me está devolviendo esto:
Código PHP:
Apellidos      Referencia Nif       Codigo  COALESCE
ARIAS ORGANERO            06208661H 842
RIVERA GOMEZ              06238975H 12476
VAQUERO LIZANO 1000       06172129X 15257   1000 
Y yo entiendo que en las dos primeras líneas, al estar vacío el campo referencia, debería devolver el valor de Nif. ¿Qué estoy haciendo mal?
Responder Con Cita
  #2  
Antiguo 12-12-2017
Avatar de Casimiro Notevi
Casimiro Notevi Casimiro Notevi is offline
Moderador
 
Registrado: sep 2004
Ubicación: En algún lugar.
Posts: 32.021
Poder: 10
Casimiro Notevi Tiene un aura espectacularCasimiro Notevi Tiene un aura espectacular
¿Has comprobado que son null, no cadena vacía ''?


Responder Con Cita
  #3  
Antiguo 12-12-2017
Avatar de Angel.Matilla
Angel.Matilla Angel.Matilla is offline
Miembro
 
Registrado: ene 2007
Posts: 1.350
Poder: 19
Angel.Matilla Va por buen camino
Cita:
Empezado por Casimiro Notevi Ver Mensaje
¿Has comprobado que son null, no cadena vacía ''?
Lo cierto es que no; he dado por supuesto que se iban a comportar igual. Y es cierto, eran candenas vacías
Responder Con Cita
  #4  
Antiguo 12-12-2017
Avatar de Casimiro Notevi
Casimiro Notevi Casimiro Notevi is offline
Moderador
 
Registrado: sep 2004
Ubicación: En algún lugar.
Posts: 32.021
Poder: 10
Casimiro Notevi Tiene un aura espectacularCasimiro Notevi Tiene un aura espectacular
Cita:
Substituting NULL with a value
The COALESCE function

The COALESCE function in Firebird 1.5 and higher can convert NULL to most anything else. This enables you to perform an on-the-fly conversion and use the result in your further processing, without the need for “if (MyExpression is null) then” or similar constructions. The function signature is:

COALESCE( Expr1, Expr2, Expr3, ... )

COALESCE returns the value of the first non-NULL expression in the argument list. If all the expressions are NULL, it returns NULL.
https://www.firebirdsql.org/manual/n...nversions.html
Responder Con Cita
  #5  
Antiguo 12-12-2017
Avatar de jhonny
jhonny jhonny is offline
Jhonny Suárez
 
Registrado: may 2003
Ubicación: Colombia
Posts: 7.058
Poder: 29
jhonny Va camino a la famajhonny Va camino a la fama
Debido a lo de la cadena vacía, puedes combinar con NULLIF, así:

Código SQL [-]
SELECT Apellidos, Referencia, Nif, Codigo, COALESCE(NullIf(Referencia, ''), NullIf(Nif, ''), NullIf(CAST(Codigo AS VARCHAR(10), '') ))
FROM Persona
ORDER BY 2,3,4,5
__________________
Lecciones de mi Madre. Tema: modificación del comportamiento, "Pará de actuar como tu padre!"

http://www.purodelphi.com/
http://www.nosolodelphi.com/
Responder Con Cita
  #6  
Antiguo 12-12-2017
Avatar de Angel.Matilla
Angel.Matilla Angel.Matilla is offline
Miembro
 
Registrado: ene 2007
Posts: 1.350
Poder: 19
Angel.Matilla Va por buen camino
Cita:
Empezado por jhonny Ver Mensaje
Debido a lo de la cadena vacía, puedes combinar con NULLIF
Gracias, no se me había ocurrido.
Responder Con Cita
Respuesta


Herramientas Buscar en Tema
Buscar en Tema:

Búsqueda Avanzada
Desplegado

Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Coalesce en índice de firebird mightydragonlor Firebird e Interbase 7 26-06-2012 22:29:31
Error en Coalesce de un Parámetro tipo Int64 gluglu Firebird e Interbase 42 17-06-2011 03:47:15
SQL CASE y COALESCE mjjj SQL 1 17-12-2008 17:37:52
Duda sobre COALESCE AGAG4 Firebird e Interbase 4 28-04-2006 22:00:57
Algo sobre COALESCE jwmoreira Firebird e Interbase 1 08-03-2005 21:23:20


La franja horaria es GMT +2. Ahora son las 01:09:36.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi