Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

If NULL Then 0 Else Other Value

Tags:

sql

oracle

I have this query that comes out with null values and numbers in the Vet_Ben_Code column. I want all the NULL to Read as 0 and all the other numbers to stay the same how do I do This. Here is the query:

SELECT STU.Term_Code,
    STU.PIDM,
    STU.Vet,
    RXR.Vet_Ben_Code

FROM
  (SELECT CST.Term_Code,
    CST.PIDM,
    SPB.Vet

  FROM
    (SELECT Term_Code,
      PIDM

     FROM CHELINK.Combined_Student_Table
     WHERE Term_Code BETWEEN '201170' AND '201670'
    )CST
  INNER JOIN
    (SELECT SPBPERS_PIDM,
      SPBPERS_VETC_FILE_NUMBER Vet

     FROM SATURN.SPBPERS
     WHERE SPBPERS_VETC_FILE_NUMBER LIKE 'Y%'
     OR SPBPERS_VETC_FILE_NUMBER LIKE 'y%'
    )SPB

  ON CST.PIDM = SPB.SPBPERS_PIDM
  )STU

LEFT JOIN
  (SELECT RXRVETN_Term_Code_VA AS Term_Code,
    RXRVETN_PIDM               AS PIDM,
    RXRVETN_Vetc_Code          AS Vet_Ben_Code

  FROM FAISMGR.RXRVETN
  WHERE RXRVETN_Term_Code_VA BETWEEN '201170' AND '201670'
  )RXR

ON STU.Term_Code    = RXR.Term_Code
AND STU. PIDM       = RXR.PIDM
like image 356
Cdubois6 Avatar asked Dec 24 '22 20:12

Cdubois6


1 Answers

You can use NVL:

NVL(col, 0)

or COALESCE:

COALESCE(col, 0)
like image 53
Gurwinder Singh Avatar answered Dec 30 '22 20:12

Gurwinder Singh