Tell me more ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

This works, but nvl AND case seem redundant. Basically, if null then 'N' else 'Y.

CHICKEN_HATCH_DATE is a DATE data type.

  select  stricken_chicken_id,
          case nvl(to_char(chicken_hatch_date),'N') 
          when 'N' then 'N'
          else 'Y'
          end chicken_hatch_date              
   from   stricken_chicken;
share|improve this question

3 Answers

up vote 2 down vote accepted

I'm not sure what's wrong with your code, but if you don't like all of those 'N''s would

  select  stricken_chicken_id,
          case when to_char(chicken_hatch_date) is null then
             'N'
          else
             'Y'
          end chicken_hatch_date              
   from   stricken_chicken;

work for you?

share|improve this answer
I tweaked this slightly.. yielding select id, case when hatch_date is null then 'N' else 'Y' end .... There is no need to perform any operation on hatch_date. – zundarz Jun 26 '12 at 1:34

If your aim is to print N for a null date why not check that directly?

SELECT
    stricken_chicken_id,
    CASE chicken_hatch_date
        WHEN NULL THEN
            'N'
        ELSE
            'Y'
    END AS "chicken_hatch_date"           
FROM
    stricken_chicken;
share|improve this answer

I think that better approach is to use "decode" instead of "case" in this example:

select stricken_chicken_id
      ,decode(chicken_hatch_date, null, 'N', 'Y') chicken_hatch_date
  from stricken_chicken;
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.