Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   SQL (https://www.clubdelphi.com/foros/forumdisplay.php?f=6)
-   -   Una de Interbase (https://www.clubdelphi.com/foros/showthread.php?t=7347)

Rabata 12-02-2004 14:09:57

Una de Interbase
 
Tengo la siguiente Consulta:

SELECT A.COD_CUENTA,
IMPORTE +
(SELECT SUM(IMPORTE)
FROM MOVIMIENTO
WHERE CERRADO = 'N' AND
CARGO = 'I' AND
FECHA = Current_Date AND
COD_CUENTA = A.COD_CUENTA) -
(SELECT SUM(IMPORTE)
FROM MOVIMIENTO
WHERE CERRADO = 'N' AND
CARGO = 'P' AND
FECHA = Current_Date AND
COD_CUENTA = A.COD_CUENTA) SALDO_CIERRE
FROM MOVIMIENTO A,
ULTIMO_SALDO B
WHERE BORRADO <> 'S' AND
CARGO = 'S' AND
A.COD_MOVIMIENTO = B.COD_MOVIMIENTO AND
A.COD_CUENTA = B.COD_CUENTA


Y cuando alguna de la s subconsultas me devuelve null, interbase me lo deja todo a null

Ej:

Cuenta Saldo_Cierre

2 null
3 3456,45
5 null

y me gustaria k donde fuese null me dijese 0, una instruccion parecida a oracle k me deja utilizar Decode k es paracido al If....

K me dejaria si fuese null k cambiara el Valor a = (Por Ejemplo)

SELECT DECODE(IMPORTE, NULL , 0)

// Sería algo como si el importe es Null, pon 0...

Muchas Gracias por Vuestra Colaboración....

haron 12-02-2004 14:39:14

pero podrias usar campos calculados para determinar el importe, en lugar de hacerlo a traves del SQL.

de todas formas creo que tu problema es el campo 'importe', ya que 'sum' creo que siempre devuelve un numero. tendrias que distinguir entre los registros quue tienen importe nulo y los que no.

__cadetill 12-02-2004 15:15:15

Prueba algo así

Código:

SELECT
  A.COD_CUENTA,
  IMPORTE +
      (SELECT SUM(IMPORTE)
      FROM MOVIMIENTO
      WHERE
        CERRADO = 'N' AND
        CARGO = 'I' AND
        FECHA = Current_Date AND
        COD_CUENTA = A.COD_CUENTA AND
        IMPORTE IS NOT NULL
) -
      (SELECT SUM(IMPORTE)
      FROM MOVIMIENTO
      WHERE
        CERRADO = 'N' AND
        CARGO = 'P' AND
        FECHA = Current_Date AND
        COD_CUENTA = A.COD_CUENTA AND
        IMPORTE IS NOT NULL
) SALDO_CIERRE
FROM MOVIMIENTO A, ULTIMO_SALDO B
WHERE
  BORRADO <> 'S' AND
  CARGO = 'S' AND
  A.COD_MOVIMIENTO = B.COD_MOVIMIENTO AND
  A.COD_CUENTA = B.COD_CUENTA


guillotmarc 12-02-2004 15:20:58

Ademas si actualizas a Firebird 1.5, puedes utilizar COALESCE(IMPORTE, 0)

Saludos.

Rabata 12-02-2004 16:46:13

Me sigue dando el mismo resultado con Importe is not null

Ya que si no hay ningún registro k cumpla la condición en la subconsulta me sigue devolviendo null, ya que en Interbase al igual k en muchos otros

234,56 + null + 3445,34 = NULL



Mi intención es k ese Null lo tome como 0 y haga lo siguiente:

234,56 + 0 + 3445,34 = .....


Muchas Gracias por Vuestra ayuda.....


La franja horaria es GMT +2. Ahora son las 04:02:31.

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