Solved

How do I handle a CDate that has a null value in a query?

Posted on 2011-09-08
4
428 Views
Last Modified: 2012-08-14
I have a query that use CDate. All is fine if there is a value in the field but if it is null I get invalid use of null.
SELECT DISTINCTROW tblsubjects.subjectid, tblupdatetable.updateid, tblupdatetable.employeeid, tblupdatetable.clientid, tblupdatetable.Date, tblupdatetable.caseupdate, tblupdatetable.checkbox1, tblupdatetable.webview, tblupdatetable.Approved, tblupdatetable.recorddate, tblupdatetable.modifieddate, "Open" AS OpenText, tblsubjects.casenumber, IIf(IsNull([subjectlast]),IIf(IsNull([subjectfirst]),[subjectcompanyname],[subjectfirst]),IIf(IsNull([subjectfirst]),[subjectlast],[subjectfirst] & " " & [subjectlast])) AS casesub, tblsubjects.casestatus, "Web Files" AS Files, CDate(nz([modifieddate],[recorddate])) AS DateStamp
FROM tblsubjects INNER JOIN tblupdatetable ON tblsubjects.subjectid = tblupdatetable.subjectid
ORDER BY CDate(nz([modifieddate],[recorddate])) DESC;

Open in new window

0
Comment
Question by:seanlhall
  • 2
  • 2
4 Comments
 
LVL 28

Expert Comment

by:strickdd
Comment Utility
Put, this around your datefield use:

CDate(IsNull(MyDateFieldHere, '1/1/1900'))
0
 

Author Comment

by:seanlhall
Comment Utility
ok that lead me to this. Date Stamp: CDate(nz([modifieddate],'1/1/1900')) which works.
I need to display the modifieddate first if the modifieddate is Null then display the recorddate if recorddate is null then dispaly default of 1/1/1990. I came up with this but it does not work. I get  Wrong number of arguments used with function.

DateStamp: CDate(nz([modifieddate],[recorddate],'1/1/1990'))
0
 
LVL 28

Accepted Solution

by:
strickdd earned 500 total points
Comment Utility
CDate(nz(IsNull(midifieddate, IsNull(recorddate, '1/1/1900'))))
0
 

Author Comment

by:seanlhall
Comment Utility
Thanks, you go me in the right direction. This worked for me.
CDate(nz([modifieddate],(nz([recorddate],'1/1/1990'))))
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Confronted with some SQL you don't know can be a daunting task. It can be even more daunting if that SQL carries some of the old secret codes used in the Ye Olde query syntax, such as: (+)     as used in Oracle;     *=     =*    as used in Sybase …
As with any other System Center product, the installation for the Authoring Tool can be quite a pain sometimes. This article serves to help you avoid making these mistakes and hopefully save you a ton of time on troubleshooting :)  Step 1: Make sur…
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…

728 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now