Search code examples
sqlnulldb2-400

SQL Select statement returning NULL


I have the following CASE statement in my SELECT clause:

       CASE HHHCRIN
       WHEN 'Y' THEN HHHINVN ELSE 'N/A'
       END AS "Credit Memo Document Number",

Can someone tell me why I get a NULL rather than N/A?


Solution

  • from the comments

    HHHCRIN is 'Y' or 'N', HHHINVN is defined as S 7,0 it is an invoice number.

    You can't return a string, be it blanks or 'N/A' when the return column is numeric.

    Since Db2 can't implicitly convert 'N/A' to a number, you get null.

    Try returning all strings...

       CASE HHHCRIN
       WHEN 'Y' THEN char(HHHINVN) ELSE 'N/A'
       END AS "Credit Memo Document Number",