Solved

Access 2007 SQL View Where Clause Help

Posted on 2014-04-02
5
510 Views
Last Modified: 2014-04-02
I need to correct the below Where clause so (access 2007 sql view) it finds all records in table
dbo_dAgentPerformanceStat that have a date 1 day less than todays date (if todays is 04/02/2014).

Right now the below WHERE code is not finding match since the Timestamp is  
2014-04-01 00:00:00  and DateSerial is calculating date as 04/01/2014.



WHERE (((dbo_dAgentPerformanceStat.Timestamp)=DateSerial(Year(Now()),Month(Now()),Day(Now()))-"1"));

dbo_dAgentPerformanceStat.Timestamp = 2014-04-01 00:00:00
DateSerial(Year(Now()),Month(Now()),Day(Now()))-"1")) = 04/01/2014


How would you create a Where clause that will compare the correct way so I find matches ?
0
Comment
Question by:thayduck
  • 2
  • 2
5 Comments
 
LVL 7

Expert Comment

by:COACHMAN99
ID: 39973282
why not use dateserial (or better still, datevalue) on both dates (after the dateadd part)?
0
 
LVL 5

Assisted Solution

by:Steve Dubyo
Steve Dubyo earned 25 total points
ID: 39973306
Hi,

You could use the Format function to change the date value to match your Timestamp column like this...

WHERE (dbo_dAgentPerformanceStat.Timestamp)=(Format(DateAdd("d",-1,Now()),"yyyy-mm-dd")+" 00:00:00");

Open in new window

0
 
LVL 7

Accepted Solution

by:
COACHMAN99 earned 75 total points
ID: 39973345
using dateadd and datevalue is good.

WHERE (Datevalue(dbo_dAgentPerformanceStat.Timestamp))=DateValue(Dateadd('d',-1,Now()));
0
 

Author Closing Comment

by:thayduck
ID: 39973381
Both solutions work and solve my problem.

Like COACHMAN99 a little better because I will not have to worry about TIMES if they happen to start showing up since I only have read access over this table.

Thanks for quick responses......
0
 
LVL 5

Expert Comment

by:Steve Dubyo
ID: 39973385
Agree that the DateValue approach is actually cleaner.  Good luck.
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

685 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