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
Solved

Access 2007 SQL View Where Clause Help

Posted on 2014-04-02
5
506 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

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
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…

808 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