Foros del Web » Programación para mayores de 30 ;) » Bases de Datos General » SQL Server »

Duda con Warning

Estas en el tema de Duda con Warning en el foro de SQL Server en Foros del Web. Ejecuto la consulta siguiente: Select max(t.tiempo) as Tiempo_Maximo, p.codp from trabajos t, conductores c, maquinas m, proyectos p where c.codc=t.codc and t.codm=m.codm and t.codp=p.codp and ...
  #1 (permalink)  
Antiguo 03/04/2006, 13:54
 
Fecha de Ingreso: abril-2005
Mensajes: 73
Antigüedad: 19 años
Puntos: 0
Duda con Warning

Ejecuto la consulta siguiente:

Select max(t.tiempo) as Tiempo_Maximo, p.codp from trabajos t, conductores c, maquinas m, proyectos p
where c.codc=t.codc and t.codm=m.codm and t.codp=p.codp and not t.codp='p01' and not t.codp='p03' group by p.codp

y no me tira error, pero me tira el siguiente Warning:

Warning: Null value eliminated from aggregate.

Que significa, o que quiere decir,


GRACIAS.CONY.
  #2 (permalink)  
Antiguo 03/04/2006, 16:14
Avatar de Mithrandir
Colaborador
 
Fecha de Ingreso: abril-2003
Mensajes: 12.106
Antigüedad: 21 años
Puntos: 25
Te advierte de esto:
Cita:
Iniciado por BOL
Null Values
Null values in a column are ignored while an aggregate function is operating. For example, the count of advances in the titles table is not the same as the count of title names because null values in the advance column are not counted.

USE pubs
SELECT COUNT(advance)
FROM titles

Here is the result set:

------------------
16

(1 row(s) affected)


USE pubs
SELECT COUNT(title)
FROM titles

Here is the result set:

------------------
18

(1 row(s) affected)

If no rows meet the condition(s) specified in the WHERE clause, COUNT returns a value of zero. The other functions all return NULL. COUNT(*), counts each row, even if all column values are NULL. Here are examples:

USE pubs
SELECT COUNT(DISTINCT title)
FROM titles
WHERE type = 'poetry'

Here is the result set:

------------------
0

(1 row(s) affected)


USE pubs
SELECT AVG(advance)
FROM titles
WHERE type = 'poetry'

Here is the result set:

------------------
(null)

(1 row(s) affected)
__________________
"El hombre, en su orgullo, creó a Dios a su imagen y semejanza."
Friedrich Nietzsche
  #3 (permalink)  
Antiguo 03/04/2006, 18:45
 
Fecha de Ingreso: abril-2005
Mensajes: 73
Antigüedad: 19 años
Puntos: 0
Respuesta

¿ Entonces lo arreglo agregando a los campos null un valor? Para que sean considerados

CONY
  #4 (permalink)  
Antiguo 03/04/2006, 19:29
Avatar de claudiovega  
Fecha de Ingreso: octubre-2003
Ubicación: Puerto Montt
Mensajes: 3.667
Antigüedad: 20 años, 6 meses
Puntos: 11
Pienso que si lo usarás con la funcion max, en realidad no importan los valores null. Para count() yo creo que si importan los null. Para avg(), si los consideras, dejandolos en cero por ejemplo, estarías alterando el promedio, bajándolo.
  #5 (permalink)  
Antiguo 04/04/2006, 14:00
Avatar de Mithrandir
Colaborador
 
Fecha de Ingreso: abril-2003
Mensajes: 12.106
Antigüedad: 21 años
Puntos: 25
Cita:
Iniciado por Cony28
¿ Entonces lo arreglo agregando a los campos null un valor? Para que sean considerados
Depende de que sea lo que quieres lograr.

Una manera para deshacerte de ellos es
Count(CASE WHEN campo IS NULL THEN 0 ELSE campo)

Pero te repito que todo depende de cual sea el comportamiento que quieres lograr.
__________________
"El hombre, en su orgullo, creó a Dios a su imagen y semejanza."
Friedrich Nietzsche
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 05:25.