Solved

SQL to select unpopulated date

Posted on 2007-03-31
10
266 Views
Last Modified: 2012-05-05
In my Access 2000 app I need to build a query with a compound condition.  The first two conditions are numeric conditions but the last condition is that I want to pull any record that does not have its date field populated.
Here is what I have so far to satidfy my first two conditions.  What would I need where I have ??????? for the third condition?  The date feild that I want to query is named 'EndStatusDate' and I want the ones that have not been populated.
'
selectString = "Select EndStatusDate From " & wkTable
whereCond = " Where [DealD] = " & gDealID
whereCond = whereCond & " and [OldStatus] = " & gPriorStatus
whereCond = whereCond & " and [EndStatusDate] = " & ??????????
'
selectString = selectString & whereCond
0
Comment
Question by:mlcktmguy
  • 3
  • 3
  • 2
  • +1
10 Comments
 
LVL 26

Expert Comment

by:jerryb30
Comment Utility
isnull([endStatusDate]
0
 
LVL 26

Accepted Solution

by:
jerryb30 earned 125 total points
Comment Utility
forgot )
isnull([endStatusDate])
0
 
LVL 1

Author Comment

by:mlcktmguy
Comment Utility
Thanks for your response.  It seems correct but when I run the following:
'
wkTable = " tblDealHistory"
'
selectString = "Select *  From " & wkTable
whereCond = " Where [DealD] = " & gDealID
whereCond = whereCond & " and [OldStatus] = " & gPriorStatus
whereCond = whereCond & " and IsNull([EndStatusDate]) "
'
selectString = selectString & whereCond
'
Dim rsOldHist As ADODB.Recordset
Set rsOldHist = New ADODB.Recordset
rsOldHist.Open selectString, CurrentProject.Connection, adOpenKeyset, adLockOptimistic

processing stops on the last statment (rsOldHist.Open...) and I get an error

'No value given for one or more required parameters.'
0
 
LVL 33

Assisted Solution

by:Mike Eghtebas
Mike Eghtebas earned 125 total points
Comment Utility
With null/empty fields in a SQL with WHERE statement, use field names not *.

Like:

     'EndStatusDate may have null/empty values--v
selectString = "Select DealD, OldStatus, nz(EndStatusDate) As StDate From " & wkTable
whereCond = " Where [DealD] = " & gDealID
whereCond = whereCond & " and [OldStatus] = " & gPriorStatus
whereCond = whereCond & " and IsNull([EndStatusDate]) "
'
selectString = selectString & whereCond

Mike
0
 
LVL 33

Expert Comment

by:Mike Eghtebas
Comment Utility
Alternates:

selectString = "Select DealD, OldStatus, nz(EndStatusDate,#1/1/111#) As StDate From " & wkTable
whereCond = " Where [DealD] = " & gDealID
whereCond = whereCond & " and [OldStatus] = " & gPriorStatus
whereCond = whereCond & " and nz(EndStatusDate,#1/1/111#)=#1/1/1111#"
'
selectString = selectString & whereCond

or maybe just (maybe):

selectString = "Select DealD, OldStatus, nz(EndStatusDate,#1/1/111#) As StDate From " & wkTable
whereCond = " Where [DealD] = " & gDealID
whereCond = whereCond & " and [OldStatus] = " & gPriorStatus
whereCond = whereCond & " and StDate = #1/1/1111#"
'
selectString = selectString & whereCond

Mike
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 1

Author Comment

by:mlcktmguy
Comment Utility
Once again thanks for responding.  One at a time I cut and pasted all three of your suggestions into the module.  I get exactly the same error as before.

This is the table definition of the table that I am querying.  Do you see anything else that might be wrong?

         RecordID                              Long Integer                             4
         DealID                                   Long Integer                             4
         OldStatus                              Long Integer                             4
         NewStatus                            Long Integer                             4
         StartStatusDate                     Date/Time                                8
         EndStatusDate                       Date/Time                                8
         Comments                              Memo                                     -
         ActualDate                             Date/Time                                8
         UserID                                     Text                                    20
0
 
LVL 119

Assisted Solution

by:Rey Obrero
Rey Obrero earned 125 total points
Comment Utility
try

selectString = "Select *  From ["& wkTable &"]
whereCond = " Where [DealD] = " & gDealID
whereCond = whereCond & " and [OldStatus] = " & gPriorStatus
whereCond = whereCond & " and IsNull([EndStatusDate]) "
0
 
LVL 119

Expert Comment

by:Rey Obrero
Comment Utility
is wkTable a variable?

selectString = "Select *  From ["& wkTable &"]
whereCond = " Where [DealD] = " & gDealID
whereCond = whereCond & " and [OldStatus] = " & gPriorStatus
whereCond = whereCond & " and IsNull([EndStatusDate]) "

selectString= selectString & whereCond

if not

selectString = "Select *  From  wkTable"
whereCond = " Where [DealD] = " & gDealID
whereCond = whereCond & " and [OldStatus] = " & gPriorStatus
whereCond = whereCond & " and IsNull([EndStatusDate]) "

selectString= selectString & whereCond
0
 
LVL 33

Expert Comment

by:Mike Eghtebas
Comment Utility
I missed the brackets around the table name. If still needed, try:

selectString = "Select DealD, OldStatus, nz(EndStatusDate,#1/1/111#) As StDate From [" & wkTable
whereCond = "] Where [DealD] = " & gDealID
whereCond = whereCond & " and [OldStatus] = " & gPriorStatus
whereCond = whereCond & " and nz(EndStatusDate,#1/1/111#)=#1/1/1111#"
'
selectString = selectString & whereCond
0
 
LVL 1

Author Comment

by:mlcktmguy
Comment Utility
I am embarrased.  jerryb30 supplied a response that was correct.  I kept getting the error because I had used the data name "DealD" instead of "DealID".  By rights I have to give the point to the first correct answer but I appreciate the answers supplied by the other responders.  They gave me some creative ways of handling date queries.  How do I resolve this?  I am going to triple the points and give the original 125 to all responders.
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Join & Write a Comment

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

762 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

10 Experts available now in Live!

Get 1:1 Help Now