Solved

handling nulls

Posted on 2009-04-03
6
677 Views
Last Modified: 2012-05-06
Hi there,
I am trying to put 1800-01-01 if date is null else populate what ever date is there
seems like it dont like nvl

Any idea why?

Thanks

SELECT
nvl(DTL_REC_CRE_DATE,'1800-01-01')
,nvl(DTL_UPDT_DATE,'1800-01-01')
from aa
0
Comment
Question by:nav29
  • 3
  • 3
6 Comments
 

Author Comment

by:nav29
ID: 24060362
even coalese dont work
0
 
LVL 45

Accepted Solution

by:
Kent Olsen earned 500 total points
ID: 24060522
Hi nav,

Coalesce should work just fine.  That's its purpose.

SELECT coalesce (DTL_REC_CRE_DATE, '1800-01-01'), coalesce (DTL_UPDT_DATE, '1800-01-01')
FROM aa;

The only restriction is that every "parameter" to the coalesce function must return compatible data types.  A properly formatted date string should suffice as a date.


Good Luck,
Kent
0
 

Author Comment

by:nav29
ID: 24060860
Data type is date
but getting errors

SQL0440N  No authorized routine named "COALESE" of type "FUNCTION" having
compatible arguments was found.  SQLSTATE=42884

SQL0440N  No authorized routine named "COALESE" of type "FUNCTION                                                      " having compatible arguments was found.

Explanation:

This occurs in a reference to routine "<routine-name>", when the
database manager cannot find a routine it can use to implement
the reference. There are several reasons why this could occur:
0
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

 
LVL 45

Expert Comment

by:Kent Olsen
ID: 24060908
Hi nav,

Check your spelling.  :)   COALESCE....

Kent
0
 

Author Comment

by:nav29
ID: 24061117
my bad thanks
0
 
LVL 45

Expert Comment

by:Kent Olsen
ID: 24061188
Hi nav,

It's amazing how many people miss this subtlety about the COALESCE function, but it can take more than 2 arguments.  The function searches the parameter list and returns the first value that is not NULL.  Most people use it to convert a single value to non-null.

  SELECT  coalesce (accounting_date, posting_date, transaction_date, current_date) FROM mytable;

That query will check the accounting_date, posting_date, and transaction_date for each row and return the first one in the list that is not NULL.  If they are all NULL, the current date is returned.


Good Luck,
Kent
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

November 2009 Recently, a question came up in the DB2 forum regarding the date format in DB2 UDB for AS/400.  Apparently in UDB LUW (Linux/Unix/Windows), the date format is a system-wide setting, and is not controlled at the session level.  I'm n…
Recursive SQL in UDB/LUW (you can use 'recursive' and 'SQL' in the same sentence) A growing number of database queries lend themselves to recursive solutions.  It's not always easy to spot when recursion is called for, especially for people una…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question