?
Solved

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

Posted on 2011-09-08
4
Medium Priority
?
616 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 28

Expert Comment

by:strickdd
ID: 36504008
Put, this around your datefield use:

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

Author Comment

by:seanlhall
ID: 36504142
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 2000 total points
ID: 36504320
CDate(nz(IsNull(midifieddate, IsNull(recorddate, '1/1/1900'))))
0
 

Author Comment

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

Featured Post

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

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

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

718 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