Ver Mensaje Individual
  #7 (permalink)  
Antiguo 19/08/2011, 19:08
Avatar de matanga
matanga
 
Fecha de Ingreso: octubre-2007
Ubicación: España
Mensajes: 1.091
Antigüedad: 16 años, 6 meses
Puntos: 85
Respuesta: Problema ISNULL

FYI, mpacheco la función NVL no evalúa un NULL cuando no existe retorno de filas, trabaja igual que la función ISNULL.

Código:
SQL> select * from t1;

        ID DATA
---------- ------------------------------
         1 1
         2 2

SQL> select nvl(id,10) from t1 where id = 10;

no rows selected
De hecho, al comparar código, este es un caso donde se aprecia mayor flexibilidad en SQL Server.

Código:
if exists (select id from t1 where id = 10) 
        select isnull(id,10) from t1 where id = 10
    else
       select 10
vs

Código:
    declare
        c integer;
    begin
        select count(*) into c from t1 where id=10;
        
        if c > 0 then
            select nvl(id,10) from t1 where id = 10
        else
            select 10 from dual;
        end if;
    end;
Saludos