Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2003
    Posts
    123

    Unanswered: nested conditions

    Hi,

    I have a SQL Server that makes imports from an Oracle database.

    I'm using queries to select the rows I want from the Oracle.

    My problem is I can't get the syntax right when I'm selecting a datecolumn.

    Pseudocode:

    SELECT DATE1 WHEN DATE1 IS NOT NULL ELSE
    SELECT DATE2 WHEN DATE2 IS NOT NULL ELSE
    SELECT DATE3 WHEN DATE3 IS NOT NULL ELSE
    SELECT '2004-11-01'

    -----

    I've tried with nested CASE but can't get it to work.

    Suggestions?

  2. #2
    Join Date
    Sep 2004
    Posts
    17
    please try this:
    select nvl (date1, nvl (date2, nvl (date3, '2004-11-01')))

    Alex

  3. #3
    Join Date
    Sep 2004
    Posts
    16

    Oracle 9i

    With Oracle 9i, you can also use the coalesce function, which returns the first non - null value from a list, all elements being of the same datatype.

    Eg:

    select coalesce (date1, date2, date3, '2004-11-01')
    from tablename

    The first non-null date value will be returned to you.

  4. #4
    Join Date
    Jul 2003
    Posts
    123
    Both solutions works like a charm---

    I'll go with the coalesce though since it's easier to use.

    Thanks!

Posting Permissions

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