Solved

Access 2007 SQL View Where Clause Help

Posted on 2014-04-02
5
499 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
Comment Utility
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
Comment Utility
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
Comment Utility
using dateadd and datevalue is good.

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

Author Closing Comment

by:thayduck
Comment Utility
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
Comment Utility
Agree that the DateValue approach is actually cleaner.  Good luck.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.

744 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

15 Experts available now in Live!

Get 1:1 Help Now