Results 1 to 5 of 5
  1. #1
    Join Date
    Oct 2002
    Posts
    34

    Unanswered: s/b easy: Case Null

    I need to do a case but am having trouble with detecting when the field in question is null. I'm trying:

    select row_added_dttm,
    case closed_dttm
    when null then 'nothing here'
    Else 'Something Here'
    End
    from tableName

    and I get "NULL " is not valid in the context where it is used". The field in question is a timestamp.

    What is the correct way to do this? Any help appreciated.

  2. #2
    Join Date
    Oct 2002
    Posts
    34
    I worked around it by using the length of the field:

    select row_added_dttm,closed_dttm,
    length(closed_dttm),
    Case length(closed_dttm)
    when 10 then 'Something Here'
    Else 'Nothing Here'
    End As whatcha
    from tablename

    This works but I'm curious about the case null.

  3. #3
    Join Date
    Dec 2002
    Posts
    134

    Re: s/b easy: Case Null

    Check case syntax in SQL Ref., you can use the following sql

    select row_added_dttm,
    case when closed_dttm is null then 'nothing here' Else 'Something Here' End
    from tableName

    regards,
    dmitri

  4. #4
    Join Date
    Oct 2002
    Posts
    34
    Works very well - thank you!

  5. #5
    Join Date
    Jan 2003
    Posts
    1,605
    Hi,

    There is also a function called COALESCE(column, value).
    If column is null then give value, else use column.

    Hope this helps,
    Grofaty

    Originally posted by elomon
    Works very well - thank you!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •