Ver Mensaje Individual
  #7 (permalink)  
Antiguo 14/04/2011, 03:42
Pelirr
 
Fecha de Ingreso: diciembre-2008
Mensajes: 233
Antigüedad: 15 años, 4 meses
Puntos: 1
Respuesta: problema con select y valor null en columna

Hola, no puede ser un and, porque le estaría diciendo: dame todas aquellas filas donde statusCode sea nulo y además distinto de (OPE,BOR,CAN), y diciéndole eso sólo salen los valores donde es nulo.

Pero no consigo que salga todo en una misma consulta. He probado directamente en la bbdd:

select * from `aodb`.`departureflight` where `aodb`.`departureflight`.joined not like 'F'
and ((`aodb`.`departureflight`.statusCode is null) or (`aodb`.`departureflight`.statusCode not in ('OPE')));
commit;

y funciona, me salen 6 registros.

Pero lo hago en el ServiceImpl:

select a from table a where a.scheduledTimeDep >=?1 and a.joined not like '%F%' and ((a.status is null) or (a.status.statusCode not in ('OPE','BOR','CAN')))

y no funciona, salen sólo 3 registros, los que tienen relleno el campo statusCode. Y si hago las consultas por separado:

select a from table a where a.scheduledTimeDep >=?1 and a.joined not like '%F%' and a.status is null;
select a from table a where a.scheduledTimeDep >=?1 and a.joined not like '%F%' and a.status.statusCode not in ('OPE','BOR','CAN')";

me funcionan, salen 3 registros en cada una. No entiendo el porqué. He intentado usar la partícula union:

select a from table a where a.scheduledTimeDep >=?1 and a.joined not like '%F%' and a.status is null union select a from DepartureFlight a where a.scheduledTimeDep >=?1 and a.joined not like '%F%' and a.status.statusCode not in ('OPE','BOR','CAN') order by a.estimatedTime

pero no funciona, la query no es correcta por lo visto.

Alguien tiene alguna idea? Necesito hacerlo todo en una misma consulta. Muchas gracias