Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Access 2007 SQL View Where Clause Help

Posted on 2014-04-02
5
Medium Priority
?
532 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 100 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 300 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

876 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